From 88b55f47b4914f7d390939e4394ec3edd42be91f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 20 Oct 2001 21:59:34 +0000 Subject: Move from timestamp to gen count file id's for finding oplocked files in a tdb. Jeremy. (This used to be commit 058ae6b58f61ef46013dd076af3a84de5fbaaab1) --- source3/smbd/oplock_linux.c | 92 ++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'source3/smbd/oplock_linux.c') diff --git a/source3/smbd/oplock_linux.c b/source3/smbd/oplock_linux.c index 8c4259ac53..f42d55d297 100644 --- a/source3/smbd/oplock_linux.c +++ b/source3/smbd/oplock_linux.c @@ -48,8 +48,9 @@ static VOLATILE sig_atomic_t fd_pending; /* the fd of the current pending signal #endif /**************************************************************************** -handle a LEASE signal, incrementing the signals_received and blocking the signal + Handle a LEASE signal, incrementing the signals_received and blocking the signal. ****************************************************************************/ + static void signal_handler(int sig, siginfo_t *info, void *unused) { BlockSignals(True, sig); @@ -59,8 +60,9 @@ static void signal_handler(int sig, siginfo_t *info, void *unused) } /**************************************************************************** -try to gain a linux capability + Try to gain a linux capability. ****************************************************************************/ + static void set_capability(unsigned capability) { #ifndef _LINUX_CAPABILITY_VERSION @@ -93,11 +95,11 @@ static void set_capability(unsigned capability) } } - /**************************************************************************** -call SETLEASE. If we get EACCES then we try setting up the right capability and -try again + Call SETLEASE. If we get EACCES then we try setting up the right capability and + try again ****************************************************************************/ + static int linux_setlease(int fd, int leasetype) { int ret; @@ -116,31 +118,27 @@ static int linux_setlease(int fd, int leasetype) return ret; } - /**************************************************************************** * Deal with the Linux kernel <--> smbd * oplock break protocol. ****************************************************************************/ + static BOOL linux_oplock_receive_message(fd_set *fds, char *buffer, int buffer_len) { - SMB_DEV_T dev; - SMB_INO_T inode; - SMB_STRUCT_STAT sbuf; BOOL ret = True; + struct files_struct *fsp; - if (signals_received == signals_processed) return False; + if (signals_received == signals_processed) + return False; - if (sys_fstat((int)fd_pending,&sbuf) == -1) { + if ((fsp = file_find_fd(fd_pending)) == NULL) { DEBUG(0,("Invalid file descriptor %d in kernel oplock break!\n", (int)fd_pending)); ret = False; goto out; } - dev = sbuf.st_dev; - inode = sbuf.st_ino; - DEBUG(3,("receive_local_message: kernel oplock break request received for \ -dev = %x, inode = %.0f\n", (unsigned int)dev, (double)inode )); +dev = %x, inode = %.0f\n", (unsigned int)fsp->dev, (double)fsp->inode )); /* * Create a kernel oplock break message. @@ -154,8 +152,9 @@ dev = %x, inode = %.0f\n", (unsigned int)dev, (double)inode )); SSVAL(buffer,OPBRK_MESSAGE_CMD_OFFSET,KERNEL_OPLOCK_BREAK_CMD); - memcpy(buffer + KERNEL_OPLOCK_BREAK_DEV_OFFSET, (char *)&dev, sizeof(dev)); - memcpy(buffer + KERNEL_OPLOCK_BREAK_INODE_OFFSET, (char *)&inode, sizeof(inode)); + memcpy(buffer + KERNEL_OPLOCK_BREAK_DEV_OFFSET, (char *)&fsp->dev, sizeof(fsp->dev)); + memcpy(buffer + KERNEL_OPLOCK_BREAK_INODE_OFFSET, (char *)&fsp->inode, sizeof(fsp->inode)); + memcpy(buffer + KERNEL_OPLOCK_BREAK_FILEID_OFFSET, (char *)&fsp->file_id, sizeof(fsp->file_id)); out: /* now we can receive more signals */ @@ -166,10 +165,10 @@ dev = %x, inode = %.0f\n", (unsigned int)dev, (double)inode )); return ret; } - /**************************************************************************** Attempt to set an kernel oplock on a file. ****************************************************************************/ + static BOOL linux_set_kernel_oplock(files_struct *fsp, int oplock_type) { if (linux_setlease(fsp->fd, F_WRLCK) == -1) { @@ -180,16 +179,16 @@ inode = %.0f. (%s)\n", return False; } - DEBUG(3,("set_file_oplock: got kernel oplock on file %s, dev = %x, inode = %.0f\n", - fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode)); + DEBUG(3,("set_file_oplock: got kernel oplock on file %s, dev = %x, inode = %.0f, file_id = %ul\n", + fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, fsp->file_id)); return True; } - /**************************************************************************** Release a kernel oplock on a file. ****************************************************************************/ + static void linux_release_kernel_oplock(files_struct *fsp) { if (DEBUGLVL(10)) { @@ -198,9 +197,9 @@ static void linux_release_kernel_oplock(files_struct *fsp) * oplock state of this file. */ int state = fcntl(fsp->fd, F_GETLEASE, 0); - dbgtext("release_kernel_oplock: file %s, dev = %x, inode = %.0f has kernel \ + dbgtext("release_kernel_oplock: file %s, dev = %x, inode = %.0f file_id = %ul has kernel \ oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->dev, - (double)fsp->inode, state ); + (double)fsp->inode, fsp->file_id, state ); } /* @@ -209,18 +208,19 @@ oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->dev, if (linux_setlease(fsp->fd, F_UNLCK) == -1) { if (DEBUGLVL(0)) { dbgtext("release_kernel_oplock: Error when removing kernel oplock on file " ); - dbgtext("%s, dev = %x, inode = %.0f. Error was %s\n", + dbgtext("%s, dev = %x, inode = %.0f, file_id = %ul. Error was %s\n", fsp->fsp_name, (unsigned int)fsp->dev, - (double)fsp->inode, strerror(errno) ); + (double)fsp->inode, fsp->file_id, strerror(errno) ); } } } - /**************************************************************************** -parse a kernel oplock message + Parse a kernel oplock message. ****************************************************************************/ -static BOOL linux_kernel_oplock_parse(char *msg_start, int msg_len, SMB_INO_T *inode, SMB_DEV_T *dev) + +static BOOL linux_kernel_oplock_parse(char *msg_start, int msg_len, SMB_INO_T *inode, + SMB_DEV_T *dev, unsigned long *file_id) { /* Ensure that the msg length is correct. */ if (msg_len != KERNEL_OPLOCK_BREAK_MSG_LEN) { @@ -229,41 +229,44 @@ static BOOL linux_kernel_oplock_parse(char *msg_start, int msg_len, SMB_INO_T *i return False; } - memcpy((char *)inode, msg_start+KERNEL_OPLOCK_BREAK_INODE_OFFSET, sizeof(*inode)); - memcpy((char *)dev, msg_start+KERNEL_OPLOCK_BREAK_DEV_OFFSET, sizeof(*dev)); + memcpy((char *)inode, msg_start+KERNEL_OPLOCK_BREAK_INODE_OFFSET, sizeof(*inode)); + memcpy((char *)dev, msg_start+KERNEL_OPLOCK_BREAK_DEV_OFFSET, sizeof(*dev)); + memcpy((char *)file_id, msg_start+KERNEL_OPLOCK_BREAK_FILEID_OFFSET, sizeof(*file_id)); - DEBUG(3,("kernel oplock break request for file dev = %x, inode = %.0f\n", - (unsigned int)*dev, (double)*inode)); + DEBUG(3,("kernel oplock break request for file dev = %x, inode = %.0f, file_id = %ul\n", + (unsigned int)*dev, (double)*inode, *file_id)); return True; } - /**************************************************************************** -see if a oplock message is waiting + See if a oplock message is waiting. ****************************************************************************/ + static BOOL linux_oplock_msg_waiting(fd_set *fds) { return signals_processed != signals_received; } /**************************************************************************** -see if the kernel supports oplocks + See if the kernel supports oplocks. ****************************************************************************/ + static BOOL linux_oplocks_available(void) { int fd, ret; fd = open("/dev/null", O_RDONLY); - if (fd == -1) return False; /* uggh! */ + if (fd == -1) + return False; /* uggh! */ ret = fcntl(fd, F_GETLEASE, 0); close(fd); return ret == F_UNLCK; } - /**************************************************************************** -setup kernel oplocks + Setup kernel oplocks. ****************************************************************************/ + struct kernel_oplocks *linux_init_kernel_oplocks(void) { static struct kernel_oplocks koplocks; @@ -274,13 +277,13 @@ struct kernel_oplocks *linux_init_kernel_oplocks(void) return NULL; } - act.sa_handler = NULL; - act.sa_sigaction = signal_handler; - act.sa_flags = SA_SIGINFO; - if (sigaction(RT_SIGNAL_LEASE, &act, NULL) != 0) { + act.sa_handler = NULL; + act.sa_sigaction = signal_handler; + act.sa_flags = SA_SIGINFO; + if (sigaction(RT_SIGNAL_LEASE, &act, NULL) != 0) { DEBUG(0,("Failed to setup RT_SIGNAL_LEASE handler\n")); return NULL; - } + } koplocks.receive_message = linux_oplock_receive_message; koplocks.set_oplock = linux_set_kernel_oplock; @@ -293,9 +296,6 @@ struct kernel_oplocks *linux_init_kernel_oplocks(void) return &koplocks; } - - - #else void oplock_linux_dummy(void) {} #endif /* HAVE_KERNEL_OPLOCKS_LINUX */ -- cgit