~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/smbd/oplock.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
21
*/
22
22
 
 
23
#define DBGC_CLASS DBGC_LOCKING
23
24
#include "includes.h"
24
25
 
25
26
/* Current number of oplocks we have outstanding. */
27
28
static int32 level_II_oplocks_open = 0;
28
29
BOOL global_client_failed_oplock_break = False;
29
30
 
30
 
extern struct timeval smb_last_time;
31
31
extern uint32 global_client_caps;
32
32
extern int smb_read_error;
33
33
 
89
89
                /* Put the kernel break info into the message. */
90
90
                SDEV_T_VAL(msg,0,fsp->dev);
91
91
                SINO_T_VAL(msg,8,fsp->inode);
92
 
                SIVAL(msg,16,fsp->file_id);
 
92
                SIVAL(msg,16,fsp->fh->file_id);
93
93
 
94
94
                /* Don't need to be root here as we're only ever
95
95
                   sending to ourselves. */
119
119
                exclusive_oplocks_open++;
120
120
        }
121
121
 
122
 
        DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, file_id = %lu, \
123
 
tv_sec = %x, tv_usec = %x\n",
124
 
                 fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, fsp->file_id,
125
 
                 (int)fsp->open_time.tv_sec, (int)fsp->open_time.tv_usec ));
 
122
        DEBUG(5,("set_file_oplock: granted oplock on file %s, 0x%x/%.0f/%lu, "
 
123
                    "tv_sec = %x, tv_usec = %x\n",
 
124
                 fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode,
 
125
                 fsp->fh->file_id, (int)fsp->open_time.tv_sec,
 
126
                 (int)fsp->open_time.tv_usec ));
126
127
 
127
128
        return True;
128
129
}
192
193
        ret = remove_share_oplock(lck, fsp);
193
194
        if (!ret) {
194
195
                DEBUG(0,("remove_oplock: failed to remove share oplock for "
195
 
                         "file %s fnum %d, dev = %x, inode = %.0f\n",
 
196
                         "file %s fnum %d, 0x%x/%.0f\n",
196
197
                         fsp->fsp_name, fsp->fnum, (unsigned int)dev,
197
198
                         (double)inode));
198
199
        }
199
200
        release_file_oplock(fsp);
200
 
        talloc_free(lck);
 
201
        TALLOC_FREE(lck);
201
202
        return ret;
202
203
}
203
204
 
226
227
        }
227
228
 
228
229
        downgrade_file_oplock(fsp);
229
 
        talloc_free(lck);
 
230
        TALLOC_FREE(lck);
230
231
        return ret;
231
232
}
232
233
 
233
234
/****************************************************************************
234
 
 Setup the listening set of file descriptors for an oplock break
235
 
 message either from the UDP socket or from the kernel. Returns the maximum
236
 
 fd used.
 
235
 Return the fd (if any) used for receiving oplock notifications.
237
236
****************************************************************************/
238
237
 
239
 
int setup_oplock_select_set( fd_set *fds)
 
238
int oplock_notify_fd(void)
240
239
{
241
 
        int maxfd = 0;
242
 
 
243
 
        if (koplocks && koplocks->notification_fd != -1) {
244
 
                FD_SET(koplocks->notification_fd, fds);
245
 
                maxfd = MAX(maxfd, koplocks->notification_fd);
 
240
        if (koplocks) {
 
241
                return koplocks->notification_fd;
246
242
        }
247
243
 
248
 
        return maxfd;
 
244
        return -1;
249
245
}
250
246
 
251
247
/****************************************************************************
282
278
 
283
279
static void wait_before_sending_break(void)
284
280
{
285
 
        struct timeval cur_tv;
286
 
        long wait_left = (long)lp_oplock_break_wait_time();
287
 
 
288
 
        if (wait_left == 0) {
289
 
                return;
290
 
        }
291
 
 
292
 
        GetTimeOfDay(&cur_tv);
293
 
 
294
 
        wait_left -= ((cur_tv.tv_sec - smb_last_time.tv_sec)*1000) +
295
 
                ((cur_tv.tv_usec - smb_last_time.tv_usec)/1000);
296
 
 
297
 
        if(wait_left > 0) {
298
 
                wait_left = MIN(wait_left, 1000);
299
 
                sys_usleep(wait_left * 1000);
 
281
        long wait_time = (long)lp_oplock_break_wait_time();
 
282
 
 
283
        if (wait_time) {
 
284
                smb_msleep(wait_time);
300
285
        }
301
286
}
302
287
 
309
294
        files_struct *fsp = NULL;
310
295
 
311
296
        if( DEBUGLVL( 3 ) ) {
312
 
                dbgtext( "initial_break_processing: called for dev = 0x%x, inode = %.0f file_id = %lu\n",
313
 
                        (unsigned int)dev, (double)inode, file_id);
 
297
                dbgtext( "initial_break_processing: called for 0x%x/%.0f/%u\n",
 
298
                        (unsigned int)dev, (double)inode, (int)file_id);
314
299
                dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
315
300
                        exclusive_oplocks_open, level_II_oplocks_open );
316
301
        }
348
333
                if( DEBUGLVL( 3 ) ) {
349
334
                        dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
350
335
                        dbgtext( "(dev = %x, inode = %.0f, file_id = %lu) has no oplock.\n",
351
 
                                (unsigned int)dev, (double)inode, fsp->file_id );
 
336
                                (unsigned int)dev, (double)inode, fsp->fh->file_id );
352
337
                        dbgtext( "Allowing break to succeed regardless.\n" );
353
338
                }
354
339
                return NULL;
420
405
        /* De-linearize incoming message. */
421
406
        message_to_share_mode_entry(&msg, buf);
422
407
 
423
 
        DEBUG(10, ("Got oplock async level 2 break message from pid %d: 0x%x/%.0f/%d\n",
424
 
                   (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
425
 
                   (int)msg.share_file_id));
 
408
        DEBUG(10, ("Got oplock async level 2 break message from pid %d: 0x%x/%.0f/%lu\n",
 
409
                   (int)procid_to_pid(&src), (unsigned int)msg.dev,
 
410
                   (double)msg.inode, msg.share_file_id));
426
411
 
427
412
        fsp = initial_break_processing(msg.dev, msg.inode,
428
413
                                       msg.share_file_id);
475
460
        /* Restore the sign state to what it was. */
476
461
        srv_oplock_set_signing(sign_state);
477
462
 
478
 
        talloc_free(break_msg);
 
463
        TALLOC_FREE(break_msg);
479
464
 
480
465
        /* Async level2 request, don't send a reply, just remove the oplock. */
481
466
        remove_oplock(fsp);
507
492
        /* De-linearize incoming message. */
508
493
        message_to_share_mode_entry(&msg, buf);
509
494
 
510
 
        DEBUG(10, ("Got oplock break message from pid %d: 0x%x/%.0f/%d\n",
511
 
                   (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
512
 
                   (int)msg.share_file_id));
 
495
        DEBUG(10, ("Got oplock break message from pid %d: 0x%x/%.0f/%lu\n",
 
496
                   (int)procid_to_pid(&src), (unsigned int)msg.dev,
 
497
                   (double)msg.inode, msg.share_file_id));
513
498
 
514
499
        fsp = initial_break_processing(msg.dev, msg.inode,
515
500
                                       msg.share_file_id);
555
540
        }
556
541
 
557
542
        if ((global_client_caps & CAP_LEVEL_II_OPLOCKS) && 
 
543
            !(msg.op_type & FORCE_OPLOCK_BREAK_TO_NONE) &&
558
544
            !koplocks && /* NOTE: we force levelII off for kernel oplocks -
559
545
                          * this will change when it is supported */
560
546
            lp_level2_oplocks(SNUM(fsp->conn))) {
583
569
        /* Restore the sign state to what it was. */
584
570
        srv_oplock_set_signing(sign_state);
585
571
 
586
 
        talloc_free(break_msg);
 
572
        TALLOC_FREE(break_msg);
587
573
 
588
574
        fsp->sent_oplock_break = break_to_level2 ? LEVEL_II_BREAK_SENT:BREAK_TO_NONE_SENT;
589
575
 
659
645
        /* Restore the sign state to what it was. */
660
646
        srv_oplock_set_signing(sign_state);
661
647
 
662
 
        talloc_free(break_msg);
 
648
        TALLOC_FREE(break_msg);
663
649
 
664
650
        fsp->sent_oplock_break = BREAK_TO_NONE_SENT;
665
651
 
686
672
        fsp->num_pending_break_messages = 0;
687
673
        if (fsp->oplock_timeout != NULL) {
688
674
                /* Remove the timed event handler. */
689
 
                talloc_free(fsp->oplock_timeout);
 
675
                TALLOC_FREE(fsp->oplock_timeout);
690
676
                fsp->oplock_timeout = NULL;
691
677
        }
692
678
        return;
710
696
        /* De-linearize incoming message. */
711
697
        message_to_share_mode_entry(&msg, buf);
712
698
 
713
 
        DEBUG(10, ("Got oplock break response from pid %d: 0x%x/%.0f/%u mid %u\n",
714
 
                   (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
715
 
                   (unsigned int)msg.share_file_id, (unsigned int)msg.op_mid));
 
699
        DEBUG(10, ("Got oplock break response from pid %d: 0x%x/%.0f/%lu mid %u\n",
 
700
                   (int)procid_to_pid(&src), (unsigned int)msg.dev,
 
701
                   (double)msg.inode, msg.share_file_id,
 
702
                   (unsigned int)msg.op_mid));
716
703
 
717
704
        /* Here's the hack from open.c, store the mid in the 'port' field */
718
705
        schedule_deferred_open_smb_message(msg.op_mid);
736
723
        /* De-linearize incoming message. */
737
724
        message_to_share_mode_entry(&msg, buf);
738
725
 
739
 
        DEBUG(10, ("Got open retry msg from pid %d: 0x%x/%.0f mid %u\n",
740
 
                   (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
 
726
        DEBUG(10, ("Got open retry msg from pid %d: 0x%x/%.0f/%lu mid %u\n",
 
727
                   (int)procid_to_pid(&src), (unsigned int)msg.dev,
 
728
                   (double)msg.inode, msg.share_file_id,
741
729
                   (unsigned int)msg.op_mid));
742
730
 
743
731
        schedule_deferred_open_smb_message(msg.op_mid);
769
757
        if (lck == NULL) {
770
758
                DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
771
759
                         "share mode entry for file %s.\n", fsp->fsp_name ));
 
760
                return;
772
761
        }
773
762
 
774
763
        DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n", 
806
795
                        DEBUG(0,("release_level_2_oplocks_on_change: PANIC. "
807
796
                                 "share mode entry %d is an exlusive "
808
797
                                 "oplock !\n", i ));
809
 
                        talloc_free(lck);
 
798
                        TALLOC_FREE(lck);
810
799
                        abort();
811
800
                }
812
801
 
821
810
        /* We let the message receivers handle removing the oplock state
822
811
           in the share mode lock db. */
823
812
 
824
 
        talloc_free(lck);
 
813
        TALLOC_FREE(lck);
825
814
}
826
815
 
827
816
/****************************************************************************
841
830
        SDEV_T_VAL(msg,28,e->dev);
842
831
        SINO_T_VAL(msg,36,e->inode);
843
832
        SIVAL(msg,44,e->share_file_id);
 
833
        SIVAL(msg,48,e->uid);
844
834
}
845
835
 
846
836
/****************************************************************************
860
850
        e->dev = DEV_T_VAL(msg,28);
861
851
        e->inode = INO_T_VAL(msg,36);
862
852
        e->share_file_id = (unsigned long)IVAL(msg,44);
 
853
        e->uid = (uint32)IVAL(msg,48);
863
854
}
864
855
 
865
856
/****************************************************************************