Fixed subtle unlocking bug when a file is closed. We need to store the
authorJeremy Allison <jra@samba.org>
Thu, 27 Apr 2000 22:23:04 +0000 (22:23 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 27 Apr 2000 22:23:04 +0000 (22:23 +0000)
smbpid used when a file was opened in the files_struct. Else we use
the wrong global_smbpid when we are closing the file and trying to
remove the brl locks - this causes the brl locks to be left when the
file is closed as the samba_context check fails.
Jeremy.
(This used to be commit 2746e5602e493e5b022764b4b839eb4d2f14363b)

source3/include/smb.h
source3/locking/brlock.c
source3/locking/locking.c
source3/smbd/open.c
source3/smbd/process.c
source3/utils/torture.c

index 6a3964e0f3eb83314aed03cf89a42a5fdbea84d9..e4415e7d220c8998dbe51fae5eec8500fde33563 100644 (file)
@@ -482,6 +482,7 @@ typedef struct files_struct
        SMB_OFF_T size;
        mode_t mode;
        uint16 vuid;
+       int smbpid;
        write_bmpx_struct *wbmpx_ptr;
        write_cache *wcp;
        struct timeval open_time;
index 68daa7e0bb1062d5393d6e48c283c12462532773..ed1f73df5ed202625b5cac81e28084a13226e3e1 100644 (file)
@@ -210,6 +210,9 @@ struct unlock_list *brl_unlock_list(TALLOC_CTX *ctx, struct unlock_list *ulhead,
         * Quit if the list is deleted.
         */
 
+       DEBUG(10,("brl_unlock_list: curr: start=%.0f,size=%.0f\n",
+               (double)ulhead->start, (double)ulhead->size ));
+
        for (i=0; i<num_locks && ulhead; i++) {
 
                struct lock_struct *lock = &locks[i];
@@ -227,9 +230,8 @@ struct unlock_list *brl_unlock_list(TALLOC_CTX *ctx, struct unlock_list *ulhead,
 
                for (ul_curr = ulhead; ul_curr;) {
 
-                       DEBUG(10,("brl_unlock_list: curr: start=%.0f,size=%.0f \
-lock: start=%.0f,size=%.0f\n", (double)ul_curr->start, (double)ul_curr->size,
-                                                               (double)lock->start, (double)lock->size ));
+                       DEBUG(10,("brl_unlock_list: lock: start=%.0f,size=%.0f:",
+                               (double)lock->start, (double)lock->size ));
 
                        if ( (ul_curr->start >= (lock->start + lock->size)) ||
                                 (lock->start > (ul_curr->start + ul_curr->size))) {
@@ -248,7 +250,7 @@ OR....
              +---------+
 **********************************************/
 
-                               DEBUG(10,("brl_unlock_list: no overlap case.\n" ));
+                               DEBUG(10,("no overlap case.\n" ));
 
                                ul_curr = ul_curr->next;
 
@@ -270,7 +272,7 @@ OR....
                                /* Save the next pointer */
                                struct unlock_list *ul_next = ul_curr->next;
 
-                               DEBUG(10,("brl_unlock_list: delete case.\n" ));
+                               DEBUG(10,("delete case.\n" ));
 
                                DLIST_REMOVE(ulhead, ul_curr);
                                if(ulhead == NULL)
@@ -302,7 +304,7 @@ BECOMES....
                                ul_curr->size = (ul_curr->start + ul_curr->size) - (lock->start + lock->size);
                                ul_curr->start = lock->start + lock->size;
 
-                               DEBUG(10,("brl_unlock_list: truncate high case: start=%.0f,size=%.0f\n",
+                               DEBUG(10,("truncate high case: start=%.0f,size=%.0f\n",
                                                                (double)ul_curr->start, (double)ul_curr->size ));
 
                                ul_curr = ul_curr->next;
@@ -329,7 +331,7 @@ BECOMES....
 
                                ul_curr->size = lock->start - ul_curr->start;
 
-                               DEBUG(10,("brl_unlock_list: truncate low case: start=%.0f,size=%.0f\n",
+                               DEBUG(10,("truncate low case: start=%.0f,size=%.0f\n",
                                                                (double)ul_curr->start, (double)ul_curr->size ));
 
                                ul_curr = ul_curr->next;
@@ -372,7 +374,7 @@ BECOMES.....
                                /* Truncate the ul_curr. */
                                ul_curr->size = lock->start - ul_curr->start;
 
-                               DEBUG(10,("brl_unlock_list: split case: curr: start=%.0f,size=%.0f \
+                               DEBUG(10,("split case: curr: start=%.0f,size=%.0f \
 new: start=%.0f,size=%.0f\n", (double)ul_curr->start, (double)ul_curr->size,
                                                                (double)ul_new->start, (double)ul_new->size ));
 
@@ -385,7 +387,7 @@ new: start=%.0f,size=%.0f\n", (double)ul_curr->start, (double)ul_curr->size,
                                 * case by forcing an abort.... Remove in production.
                                 */
 
-                               smb_panic("brl_unlock_list: logic flaw in cases...\n");
+                               smb_panic("logic flaw in cases...\n");
                        }
                } /* end for ( ul_curr = ulhead; ul_curr;) */
        } /* end for (i=0; i<num_locks && ul_head; i++) */
@@ -422,7 +424,10 @@ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
        tdb_lockchain(tdb, kbuf);
        dbuf = tdb_fetch(tdb, kbuf);
 
-       if (!dbuf.dptr) goto fail;
+       if (!dbuf.dptr) {
+               DEBUG(0,("brl_unlock: tdb_fetch failed !\n"));
+               goto fail;
+       }
 
        context.smbpid = smbpid;
        context.pid = pid;
@@ -435,6 +440,18 @@ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
 
                struct lock_struct *lock = &locks[i];
 
+#if 0
+               /* JRATEST - DEBUGGING INFO */
+               if(!brl_same_context(&lock->context, &context)) {
+                       DEBUG(10,("brl_unlock: Not same context. l_smbpid = %u, l_pid = %u, l_tid = %u: \
+smbpid = %u, pid = %u, tid = %u\n",
+                               lock->context.smbpid, lock->context.pid, lock->context.tid,
+                               context.smbpid, context.pid, context.tid ));
+
+               }
+               /* JRATEST */
+#endif
+
                if (brl_same_context(&lock->context, &context) &&
                    lock->fnum == fnum &&
                    lock->start == start &&
index 9d407bf16b5217c707e5bec3e966ed20a710d299..b6b34138e369e22059d17cbfd9fdc22e9b75f34a 100644 (file)
@@ -41,8 +41,6 @@ extern int DEBUGLEVEL;
 /* the locking database handle */
 static TDB_CONTEXT *tdb;
 
-int global_smbpid;
-
 /*
  * Doubly linked list to hold pending closes needed for
  * POSIX locks. This may be changed to use a hash table (as
@@ -569,7 +567,7 @@ BOOL is_locked(files_struct *fsp,connection_struct *conn,
                return(False);
 
        ret = !brl_locktest(fsp->dev, fsp->inode, 
-                            global_smbpid, getpid(), conn->cnum, 
+                            fsp->smbpid, getpid(), conn->cnum, 
                             offset, count, lock_type);
 
        /*
@@ -607,7 +605,7 @@ BOOL do_lock(files_struct *fsp,connection_struct *conn,
 
        if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) {
                ok = brl_lock(fsp->dev, fsp->inode, fsp->fnum,
-                             global_smbpid, getpid(), conn->cnum, 
+                             fsp->smbpid, getpid(), conn->cnum, 
                              offset, count, 
                              lock_type);
 
@@ -627,7 +625,7 @@ BOOL do_lock(files_struct *fsp,connection_struct *conn,
                                 * lock entry.
                                 */
                                (void)brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
-                                                               global_smbpid, getpid(), conn->cnum, 
+                                                               fsp->smbpid, getpid(), conn->cnum, 
                                                                offset, count);
                        }
                }
@@ -676,9 +674,10 @@ BOOL do_unlock(files_struct *fsp,connection_struct *conn,
        pid = getpid();
 
        ok = brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
-                       global_smbpid, pid, conn->cnum, offset, count);
+                       fsp->smbpid, pid, conn->cnum, offset, count);
    
        if (!ok) {
+               DEBUG(10,("do_unlock: returning ERRlock.\n" ));
                *eclass = ERRDOS;
                *ecode = ERRlock;
                return False;
index 737b9b5ef3684f62d259db377ab59abe4915888b..92bba76619af28e48a555043995109ec1da1f3ff 100644 (file)
@@ -26,6 +26,7 @@ extern int DEBUGLEVEL;
 extern pstring sesssetup_user;
 extern uint16 global_oplock_port;
 extern BOOL global_client_failed_oplock_break;
+extern int global_smbpid;
 
 /****************************************************************************
  fd support routines - attempt to do a dos_open.
@@ -164,6 +165,7 @@ static BOOL open_file(files_struct *fsp,connection_struct *conn,
        fsp->dev = sbuf.st_dev;
        GetTimeOfDay(&fsp->open_time);
        fsp->vuid = current_user.vuid;
+       fsp->smbpid = global_smbpid;
        fsp->size = 0;
        fsp->pos = -1;
        fsp->can_lock = True;
@@ -797,6 +799,7 @@ files_struct *open_file_stat(connection_struct *conn,
        fsp->mode = 0;
        GetTimeOfDay(&fsp->open_time);
        fsp->vuid = current_user.vuid;
+       fsp->smbpid = global_smbpid;
        fsp->size = 0;
        fsp->pos = -1;
        fsp->can_lock = False;
@@ -920,6 +923,7 @@ files_struct *open_directory(connection_struct *conn,
        fsp->mode = 0;
        GetTimeOfDay(&fsp->open_time);
        fsp->vuid = current_user.vuid;
+       fsp->smbpid = global_smbpid;
        fsp->size = 0;
        fsp->pos = -1;
        fsp->can_lock = True;
index f37855028295f4f836720333914f0ad8477c1529..77e6fc2aa794413c99cab2090531ee89d150696c 100644 (file)
@@ -28,6 +28,7 @@ struct timeval smb_last_time;
 static char *InBuffer = NULL;
 char *OutBuffer = NULL;
 char *last_inbuf = NULL;
+int global_smbpid;
 
 /* 
  * Size of data we can send to client. Set
@@ -418,7 +419,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize
   static int num_smb_messages = 
     sizeof(smb_messages) / sizeof(struct smb_message_struct);
   int match;
-  extern int global_smbpid;
 
   if (pid == (pid_t)-1)
     pid = getpid();
index deeb304804d1223070e1ee20a544d2986b31a742..1a9e75797772e152c8bf06221dc3cd667c2a0084 100644 (file)
@@ -930,7 +930,7 @@ static void run_locktest4(int dummy)
 
  fail:
        cli_close(&cli1, fnum1);
-       cli_close(&cli1, fnum2);
+       cli_close(&cli2, fnum2);
        cli_unlink(&cli1, fname);
        close_connection(&cli1);
        close_connection(&cli2);