From 2c1b861539c15491593625920058e06452cd3747 Mon Sep 17 00:00:00 2001 From: Steve French Date: Thu, 16 Oct 2008 18:35:21 +0000 Subject: [CIFS] Add nodfs mount option Older samba server (eg. 3.0.24 from Debian etch) don't work correctly, if DFS paths are used. Such server claim that they support DFS, but fail to process some requests with DFS paths. Starting with Linux 2.6.26, the cifs clients starts sending DFS paths in such situations, rendering it unuseable with older samba servers. The nodfs mount options forces a share to be used with non DFS paths, even if the server claims, that it supports it. Signed-off-by: Martin Koegler Acked-by: Jeff Layton Acked-by: Igor Mammedov Signed-off-by: Steve French --- fs/cifs/README | 3 +++ fs/cifs/connect.c | 9 +++++++++ 2 files changed, 12 insertions(+) (limited to 'fs') diff --git a/fs/cifs/README b/fs/cifs/README index bd2343d4c6a..cbe26fe4012 100644 --- a/fs/cifs/README +++ b/fs/cifs/README @@ -463,6 +463,9 @@ A partial list of the supported mount options follows: with cifs style mandatory byte range locks (and most cifs servers do not yet support requesting advisory byte range locks). + nodfs Disable DFS (global name space support) even if the + server claims to support it. This can help work around + a problem with parsing of DFS paths with Samba 3.0.24 server. remount remount the share (often used to change from ro to rw mounts or vice versa) cifsacl Report mode bits (e.g. on stat) based on the Windows ACL for diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 4c13bcdb92a..17ca8ce81bb 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -90,6 +90,7 @@ struct smb_vol { bool nocase:1; /* request case insensitive filenames */ bool nobrl:1; /* disable sending byte range locks to srv */ bool seal:1; /* request transport encryption on share */ + bool nodfs:1; unsigned int rsize; unsigned int wsize; unsigned int sockopt; @@ -1218,6 +1219,8 @@ cifs_parse_mount_options(char *options, const char *devname, vol->sfu_emul = 1; } else if (strnicmp(data, "nosfu", 5) == 0) { vol->sfu_emul = 0; + } else if (strnicmp(data, "nodfs", 5) == 0) { + vol->nodfs = 1; } else if (strnicmp(data, "posixpaths", 10) == 0) { vol->posix_paths = 1; } else if (strnicmp(data, "noposixpaths", 12) == 0) { @@ -2197,6 +2200,12 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, volume_info.UNC, tcon, cifs_sb->local_nls); cFYI(1, ("CIFS Tcon rc = %d", rc)); + if (volume_info.nodfs) { + tcon->Flags &= + ~SMB_SHARE_IS_IN_DFS; + cFYI(1, ("DFS disabled (%d)", + tcon->Flags)); + } } if (!rc) { atomic_inc(&pSesInfo->inUse); -- cgit v1.2.3 From 469ee614aaa367d9cde01cbdd2027212f56c6cc6 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Thu, 16 Oct 2008 18:46:39 +0000 Subject: [CIFS] eliminate usage of kthread_stop for cifsd When cifs_demultiplex_thread was converted to a kthread based kernel thread, great pains were taken to make it so that kthread_stop would be used to bring it down. This just added unnecessary complexity since we needed to use a signal anyway to break out of kernel_recvmsg. Also, cifs_demultiplex_thread does a bit of cleanup as it's exiting, and we need to be certain that this gets done. It's possible for a kthread to exit before its main function is ever run if kthread_stop is called soon after its creation. While I'm not sure that this is a real problem with cifsd now, it could be at some point in the future if cifs_mount is ever changed to bring down the thread quickly. The upshot here is that using kthread_stop to bring down the thread just adds extra complexity with no real benefit. This patch changes the code to use the original method to bring down the thread, but still leaves it so that the thread is actually started with kthread_run. This seems to fix the deadlock caused by the reproducer in this bug report: https://bugzilla.samba.org/show_bug.cgi?id=5720 Signed-off-by: Jeff Layton Signed-off-by: Steve French --- fs/cifs/connect.c | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) (limited to 'fs') diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 17ca8ce81bb..1126f7ab460 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -125,7 +125,7 @@ cifs_reconnect(struct TCP_Server_Info *server) struct mid_q_entry *mid_entry; spin_lock(&GlobalMid_Lock); - if (kthread_should_stop()) { + if (server->tcpStatus == CifsExiting) { /* the demux thread will exit normally next time through the loop */ spin_unlock(&GlobalMid_Lock); @@ -185,7 +185,8 @@ cifs_reconnect(struct TCP_Server_Info *server) spin_unlock(&GlobalMid_Lock); up(&server->tcpSem); - while ((!kthread_should_stop()) && (server->tcpStatus != CifsGood)) { + while ((server->tcpStatus != CifsExiting) && + (server->tcpStatus != CifsGood)) { try_to_freeze(); if (server->protocolType == IPV6) { rc = ipv6_connect(&server->addr.sockAddr6, @@ -202,7 +203,7 @@ cifs_reconnect(struct TCP_Server_Info *server) } else { atomic_inc(&tcpSesReconnectCount); spin_lock(&GlobalMid_Lock); - if (!kthread_should_stop()) + if (server->tcpStatus != CifsExiting) server->tcpStatus = CifsGood; server->sequence_number = 0; spin_unlock(&GlobalMid_Lock); @@ -357,7 +358,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) GFP_KERNEL); set_freezable(); - while (!kthread_should_stop()) { + while (server->tcpStatus != CifsExiting) { if (try_to_freeze()) continue; if (bigbuf == NULL) { @@ -398,7 +399,7 @@ incomplete_rcv: kernel_recvmsg(csocket, &smb_msg, &iov, 1, pdu_length, 0 /* BB other flags? */); - if (kthread_should_stop()) { + if (server->tcpStatus == CifsExiting) { break; } else if (server->tcpStatus == CifsNeedReconnect) { cFYI(1, ("Reconnect after server stopped responding")); @@ -523,7 +524,7 @@ incomplete_rcv: total_read += length) { length = kernel_recvmsg(csocket, &smb_msg, &iov, 1, pdu_length - total_read, 0); - if (kthread_should_stop() || + if ((server->tcpStatus == CifsExiting) || (length == -EINTR)) { /* then will exit */ reconnect = 2; @@ -652,14 +653,6 @@ multi_t2_fnd: spin_unlock(&GlobalMid_Lock); wake_up_all(&server->response_q); - /* don't exit until kthread_stop is called */ - set_current_state(TASK_UNINTERRUPTIBLE); - while (!kthread_should_stop()) { - schedule(); - set_current_state(TASK_UNINTERRUPTIBLE); - } - set_current_state(TASK_RUNNING); - /* check if we have blocked requests that need to free */ /* Note that cifs_max_pending is normally 50, but can be set at module install time to as little as two */ @@ -2234,14 +2227,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, spin_lock(&GlobalMid_Lock); srvTcp->tcpStatus = CifsExiting; spin_unlock(&GlobalMid_Lock); - if (srvTcp->tsk) { - /* If we could verify that kthread_stop would - always wake up processes blocked in - tcp in recv_mesg then we could remove the - send_sig call */ - force_sig(SIGKILL, srvTcp->tsk); - kthread_stop(srvTcp->tsk); - } + force_sig(SIGKILL, srvTcp->tsk); } /* If find_unc succeeded then rc == 0 so we can not end */ if (tcon) /* up accidently freeing someone elses tcon struct */ @@ -2255,18 +2241,18 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, /* if the socketUseCount is now zero */ if ((temp_rc == -ESHUTDOWN) && (pSesInfo->server) && - (pSesInfo->server->tsk)) { + (pSesInfo->server->tsk)) force_sig(SIGKILL, pSesInfo->server->tsk); - kthread_stop(pSesInfo->server->tsk); - } } else { cFYI(1, ("No session or bad tcon")); if ((pSesInfo->server) && (pSesInfo->server->tsk)) { + spin_lock(&GlobalMid_Lock); + srvTcp->tcpStatus = CifsExiting; + spin_unlock(&GlobalMid_Lock); force_sig(SIGKILL, pSesInfo->server->tsk); - kthread_stop(pSesInfo->server->tsk); } } sesInfoFree(pSesInfo); @@ -3577,10 +3563,8 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb) return 0; } else if (rc == -ESHUTDOWN) { cFYI(1, ("Waking up socket by sending signal")); - if (cifsd_task) { + if (cifsd_task) force_sig(SIGKILL, cifsd_task); - kthread_stop(cifsd_task); - } rc = 0; } /* else - we have an smb session left on this socket do not kill cifsd */ @@ -3710,7 +3694,9 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo, cERROR(1, ("Send error in SessSetup = %d", rc)); } else { cFYI(1, ("CIFS Session Established successfully")); + spin_lock(&GlobalMid_Lock); pSesInfo->status = CifsGood; + spin_unlock(&GlobalMid_Lock); } ss_err_exit: -- cgit v1.2.3 From dd1db2dedc4f6ad736fbba5aa6ecfe6e7c8ee0f4 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Thu, 16 Oct 2008 19:27:12 -0400 Subject: cifs: don't use CREATE_DELETE_ON_CLOSE in cifs_rename_pending_delete cifs: don't use CREATE_DELETE_ON_CLOSE in cifs_rename_pending_delete CREATE_DELETE_ON_CLOSE apparently has different semantics than when you set the DELETE_ON_CLOSE bit after opening the file. Setting it in the open says "delete this file as soon as this filehandle is closed". That's not what we want for cifs_rename_pending_delete. Don't set this bit in the CreateFlags. Experimentation shows that setting this flag in the SET_FILE_INFO call has no effect. Signed-off-by: Jeff Layton Signed-off-by: Steve French --- fs/cifs/inode.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'fs') diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index a8c833345fc..fe4f2ee97b6 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -784,8 +784,7 @@ cifs_rename_pending_delete(char *full_path, struct inode *inode, int xid) FILE_BASIC_INFO *info_buf; rc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN, - DELETE|FILE_WRITE_ATTRIBUTES, - CREATE_NOT_DIR|CREATE_DELETE_ON_CLOSE, + DELETE|FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR, &netfid, &oplock, NULL, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); if (rc != 0) @@ -810,17 +809,23 @@ cifs_rename_pending_delete(char *full_path, struct inode *inode, int xid) goto out_close; cifsInode->cifsAttrs = dosattr; - /* silly-rename the file */ - CIFSSMBRenameOpenFile(xid, tcon, netfid, NULL, cifs_sb->local_nls, + /* rename the file */ + rc = CIFSSMBRenameOpenFile(xid, tcon, netfid, NULL, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); + if (rc != 0) + goto out; /* set DELETE_ON_CLOSE */ rc = CIFSSMBSetFileDisposition(xid, tcon, true, netfid, current->tgid); /* * some samba versions return -ENOENT when we try to set the file - * disposition here. Likely a samba bug, but work around it for now + * disposition here. Likely a samba bug, but work around it for now. + * This means that some cifsXXX files may hang around after they + * shouldn't. + * + * BB: remove this once fixed samba servers are in the field */ if (rc == -ENOENT) rc = 0; -- cgit v1.2.3 From 9a8165fce724d1aba21e2c713ac6ba11dbfecafa Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Fri, 17 Oct 2008 21:03:20 -0400 Subject: cifs: track DeletePending flag in cifsInodeInfo cifs: track DeletePending flag in cifsInodeInfo The QPathInfo call returns a flag that indicates whether DELETE_ON_CLOSE is set. Track it in the cifsInodeInfo. Signed-off-by: Jeff Layton Signed-off-by: Steve French --- fs/cifs/cifsfs.c | 1 + fs/cifs/cifsglob.h | 1 + fs/cifs/cifssmb.c | 2 ++ fs/cifs/inode.c | 1 + 4 files changed, 5 insertions(+) (limited to 'fs') diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 25ecbd5b040..c6aad775dd6 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -309,6 +309,7 @@ cifs_alloc_inode(struct super_block *sb) file data or metadata */ cifs_inode->clientCanCacheRead = false; cifs_inode->clientCanCacheAll = false; + cifs_inode->delete_pending = false; cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ /* Can not set i_flags here - they get immediately overwritten diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 0d22479d99b..178f733a368 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -353,6 +353,7 @@ struct cifsInodeInfo { bool clientCanCacheRead:1; /* read oplock */ bool clientCanCacheAll:1; /* read and writebehind oplock */ bool oplockPending:1; + bool delete_pending:1; /* DELETE_ON_CLOSE is set */ struct inode vfs_inode; }; diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 6f4ffe15d68..843a85fb8b9 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -1309,6 +1309,7 @@ OldOpenRetry: cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); pfile_info->EndOfFile = pfile_info->AllocationSize; pfile_info->NumberOfLinks = cpu_to_le32(1); + pfile_info->DeletePending = 0; } } @@ -1410,6 +1411,7 @@ openRetry: pfile_info->AllocationSize = pSMBr->AllocationSize; pfile_info->EndOfFile = pSMBr->EndOfFile; pfile_info->NumberOfLinks = cpu_to_le32(1); + pfile_info->DeletePending = 0; } } diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index fe4f2ee97b6..dea9eeb58b0 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -506,6 +506,7 @@ int cifs_get_inode_info(struct inode **pinode, inode = *pinode; cifsInfo = CIFS_I(inode); cifsInfo->cifsAttrs = attr; + cifsInfo->delete_pending = pfindData->DeletePending ? true : false; cFYI(1, ("Old time %ld", cifsInfo->time)); cifsInfo->time = jiffies; cFYI(1, ("New time %ld", cifsInfo->time)); -- cgit v1.2.3 From 3270958b717a13d0228803254609c19184854b9b Mon Sep 17 00:00:00 2001 From: Steve French Date: Mon, 20 Oct 2008 00:44:19 +0000 Subject: [CIFS] undo changes in cifs_rename_pending_delete if it errors out The cifs_rename_pending_delete process involves multiple steps. If it fails and we're going to return error, we don't want to leave things in a half-finished state. Add code to the function to undo changes if a call fails. Signed-off-by: Jeff Layton Signed-off-by: Steve French --- fs/cifs/CHANGES | 8 +++++ fs/cifs/cifsfs.h | 2 +- fs/cifs/inode.c | 102 ++++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 79 insertions(+), 33 deletions(-) (limited to 'fs') diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES index 06e521a945c..a7255751ffb 100644 --- a/fs/cifs/CHANGES +++ b/fs/cifs/CHANGES @@ -1,3 +1,10 @@ +Version 1.55 +------------ +Various fixes to make delete of open files behavior more predictable +(when delete of an open file fails we mark the file as "delete-on-close" +in a way that more servers accept, but only if we can first rename the +file to a temporary name) + Version 1.54 ------------ Fix premature write failure on congested networks (we would give up @@ -13,6 +20,7 @@ on dns_upcall (resolving DFS referralls). Fix plain text password authentication (requires setting SecurityFlags to 0x30030 to enable lanman and plain text though). Fix writes to be at correct offset when file is open with O_APPEND and file is on a directio (forcediretio) mount. +Fix bug in rewinding readdir directory searches. Add nodfs mount option. Version 1.53 ------------ diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index f7b4a5cd837..074de0b5064 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h @@ -101,5 +101,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); extern const struct export_operations cifs_export_ops; #endif /* EXPERIMENTAL */ -#define CIFS_VERSION "1.54" +#define CIFS_VERSION "1.55" #endif /* _CIFSFS_H */ diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index dea9eeb58b0..232ab16d7fd 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -773,16 +773,17 @@ out: * anything else. */ static int -cifs_rename_pending_delete(char *full_path, struct inode *inode, int xid) +cifs_rename_pending_delete(char *full_path, struct dentry *dentry, int xid) { int oplock = 0; int rc; __u16 netfid; + struct inode *inode = dentry->d_inode; struct cifsInodeInfo *cifsInode = CIFS_I(inode); struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifsTconInfo *tcon = cifs_sb->tcon; - __u32 dosattr; - FILE_BASIC_INFO *info_buf; + __u32 dosattr, origattr; + FILE_BASIC_INFO *info_buf = NULL; rc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN, DELETE|FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR, @@ -791,50 +792,87 @@ cifs_rename_pending_delete(char *full_path, struct inode *inode, int xid) if (rc != 0) goto out; - /* set ATTR_HIDDEN and clear ATTR_READONLY */ - cifsInode = CIFS_I(inode); - dosattr = cifsInode->cifsAttrs & ~ATTR_READONLY; + origattr = cifsInode->cifsAttrs; + if (origattr == 0) + origattr |= ATTR_NORMAL; + + dosattr = origattr & ~ATTR_READONLY; if (dosattr == 0) dosattr |= ATTR_NORMAL; dosattr |= ATTR_HIDDEN; - info_buf = kzalloc(sizeof(*info_buf), GFP_KERNEL); - if (info_buf == NULL) { - rc = -ENOMEM; - goto out_close; + /* set ATTR_HIDDEN and clear ATTR_READONLY, but only if needed */ + if (dosattr != origattr) { + info_buf = kzalloc(sizeof(*info_buf), GFP_KERNEL); + if (info_buf == NULL) { + rc = -ENOMEM; + goto out_close; + } + info_buf->Attributes = cpu_to_le32(dosattr); + rc = CIFSSMBSetFileInfo(xid, tcon, info_buf, netfid, + current->tgid); + /* although we would like to mark the file hidden + if that fails we will still try to rename it */ + if (rc != 0) { + cifsInode->cifsAttrs = dosattr; + else + dosattr = origattr; /* since not able to change them */ } - info_buf->Attributes = cpu_to_le32(dosattr); - rc = CIFSSMBSetFileInfo(xid, tcon, info_buf, netfid, current->tgid); - kfree(info_buf); - if (rc != 0) - goto out_close; - cifsInode->cifsAttrs = dosattr; /* rename the file */ rc = CIFSSMBRenameOpenFile(xid, tcon, netfid, NULL, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); - if (rc != 0) - goto out; - - /* set DELETE_ON_CLOSE */ - rc = CIFSSMBSetFileDisposition(xid, tcon, true, netfid, current->tgid); + if (rc != 0) { + rc = -ETXTBSY; + goto undo_setattr; + } - /* - * some samba versions return -ENOENT when we try to set the file - * disposition here. Likely a samba bug, but work around it for now. - * This means that some cifsXXX files may hang around after they - * shouldn't. - * - * BB: remove this once fixed samba servers are in the field - */ - if (rc == -ENOENT) - rc = 0; + /* try to set DELETE_ON_CLOSE */ + if (!cifsInode->delete_pending) { + rc = CIFSSMBSetFileDisposition(xid, tcon, true, netfid, + current->tgid); + /* + * some samba versions return -ENOENT when we try to set the + * file disposition here. Likely a samba bug, but work around + * it for now. This means that some cifsXXX files may hang + * around after they shouldn't. + * + * BB: remove this hack after more servers have the fix + */ + if (rc == -ENOENT) + rc = 0; + else if (rc != 0) { + rc = -ETXTBSY; + goto undo_rename; + } + cifsInode->delete_pending = true; + } out_close: CIFSSMBClose(xid, tcon, netfid); out: + kfree(info_buf); return rc; + + /* + * reset everything back to the original state. Don't bother + * dealing with errors here since we can't do anything about + * them anyway. + */ +undo_rename: + CIFSSMBRenameOpenFile(xid, tcon, netfid, dentry->d_name.name, + cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & + CIFS_MOUNT_MAP_SPECIAL_CHR); +undo_setattr: + if (dosattr != origattr) { + info_buf->Attributes = cpu_to_le32(origattr); + if (!CIFSSMBSetFileInfo(xid, tcon, info_buf, netfid, + current->tgid)) + cifsInode->cifsAttrs = origattr; + } + + goto out_close; } int cifs_unlink(struct inode *dir, struct dentry *dentry) @@ -884,7 +922,7 @@ psx_del_no_retry: } else if (rc == -ENOENT) { d_drop(dentry); } else if (rc == -ETXTBSY) { - rc = cifs_rename_pending_delete(full_path, inode, xid); + rc = cifs_rename_pending_delete(full_path, dentry, xid); if (rc == 0) drop_nlink(inode); } else if (rc == -EACCES && dosattr == 0) { -- cgit v1.2.3 From 413460980ea7796582bce672be85879be0865ada Mon Sep 17 00:00:00 2001 From: Steve French Date: Mon, 20 Oct 2008 18:24:42 +0000 Subject: [CIFS] fix build error Signed-off-by: Steve French --- fs/cifs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 232ab16d7fd..23cca214ede 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -813,7 +813,7 @@ cifs_rename_pending_delete(char *full_path, struct dentry *dentry, int xid) current->tgid); /* although we would like to mark the file hidden if that fails we will still try to rename it */ - if (rc != 0) { + if (rc != 0) cifsInode->cifsAttrs = dosattr; else dosattr = origattr; /* since not able to change them */ -- cgit v1.2.3 From 14121bdccc17b8c0e4368a9c0e4f82c3dd47f240 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Mon, 20 Oct 2008 14:45:22 -0400 Subject: cifs: make cifs_rename handle -EACCES errors cifs: make cifs_rename handle -EACCES errors Some servers seem to return -EACCES when attempting to rename one open file on top of another. Refactor the cifs_rename logic to attempt to rename the target file out of the way in this situation. This also fixes the "unlink_target" logic to be undoable if the subsequent rename fails. Signed-off-by: Jeff Layton Signed-off-by: Steve French --- fs/cifs/inode.c | 174 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 122 insertions(+), 52 deletions(-) (limited to 'fs') diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 23cca214ede..8ac4eabc1f8 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -1285,22 +1285,24 @@ cifs_do_rename(int xid, struct dentry *from_dentry, const char *fromPath, return rc; } -int cifs_rename(struct inode *source_inode, struct dentry *source_direntry, - struct inode *target_inode, struct dentry *target_direntry) +int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, + struct inode *target_dir, struct dentry *target_dentry) { char *fromName = NULL; char *toName = NULL; struct cifs_sb_info *cifs_sb_source; struct cifs_sb_info *cifs_sb_target; - struct cifsTconInfo *pTcon; + struct cifsTconInfo *tcon; + struct cifsInodeInfo *target_cinode; FILE_UNIX_BASIC_INFO *info_buf_source = NULL; FILE_UNIX_BASIC_INFO *info_buf_target; - int xid; - int rc; + __u16 dstfid; + int xid, rc, tmprc, oplock = 0; + bool delete_already_pending; - cifs_sb_target = CIFS_SB(target_inode->i_sb); - cifs_sb_source = CIFS_SB(source_inode->i_sb); - pTcon = cifs_sb_source->tcon; + cifs_sb_target = CIFS_SB(target_dir->i_sb); + cifs_sb_source = CIFS_SB(source_dir->i_sb); + tcon = cifs_sb_source->tcon; xid = GetXid(); @@ -1308,7 +1310,7 @@ int cifs_rename(struct inode *source_inode, struct dentry *source_direntry, * BB: this might be allowed if same server, but different share. * Consider adding support for this */ - if (pTcon != cifs_sb_target->tcon) { + if (tcon != cifs_sb_target->tcon) { rc = -EXDEV; goto cifs_rename_exit; } @@ -1317,65 +1319,133 @@ int cifs_rename(struct inode *source_inode, struct dentry *source_direntry, * we already have the rename sem so we do not need to * grab it again here to protect the path integrity */ - fromName = build_path_from_dentry(source_direntry); + fromName = build_path_from_dentry(source_dentry); if (fromName == NULL) { rc = -ENOMEM; goto cifs_rename_exit; } - toName = build_path_from_dentry(target_direntry); + toName = build_path_from_dentry(target_dentry); if (toName == NULL) { rc = -ENOMEM; goto cifs_rename_exit; } - rc = cifs_do_rename(xid, source_direntry, fromName, - target_direntry, toName); + rc = cifs_do_rename(xid, source_dentry, fromName, + target_dentry, toName); - if (rc == -EEXIST) { - if (pTcon->unix_ext) { - /* - * Are src and dst hardlinks of same inode? We can - * only tell with unix extensions enabled - */ - info_buf_source = - kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), - GFP_KERNEL); - if (info_buf_source == NULL) - goto unlink_target; - - info_buf_target = info_buf_source + 1; - rc = CIFSSMBUnixQPathInfo(xid, pTcon, fromName, - info_buf_source, - cifs_sb_source->local_nls, - cifs_sb_source->mnt_cifs_flags & - CIFS_MOUNT_MAP_SPECIAL_CHR); - if (rc != 0) - goto unlink_target; - - rc = CIFSSMBUnixQPathInfo(xid, pTcon, - toName, info_buf_target, - cifs_sb_target->local_nls, - /* remap based on source sb */ - cifs_sb_source->mnt_cifs_flags & - CIFS_MOUNT_MAP_SPECIAL_CHR); + if (rc == -EEXIST && tcon->unix_ext) { + /* + * Are src and dst hardlinks of same inode? We can + * only tell with unix extensions enabled + */ + info_buf_source = + kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), + GFP_KERNEL); + if (info_buf_source == NULL) { + rc = -ENOMEM; + goto cifs_rename_exit; + } + + info_buf_target = info_buf_source + 1; + rc = CIFSSMBUnixQPathInfo(xid, tcon, fromName, + info_buf_source, + cifs_sb_source->local_nls, + cifs_sb_source->mnt_cifs_flags & + CIFS_MOUNT_MAP_SPECIAL_CHR); + if (rc != 0) + goto unlink_target; - if (rc == 0 && (info_buf_source->UniqueId == - info_buf_target->UniqueId)) - /* same file, POSIX says that this is a noop */ - goto cifs_rename_exit; - } /* else ... BB we could add the same check for Windows by + rc = CIFSSMBUnixQPathInfo(xid, tcon, + toName, info_buf_target, + cifs_sb_target->local_nls, + /* remap based on source sb */ + cifs_sb_source->mnt_cifs_flags & + CIFS_MOUNT_MAP_SPECIAL_CHR); + + if (rc == 0 && (info_buf_source->UniqueId == + info_buf_target->UniqueId)) + /* same file, POSIX says that this is a noop */ + goto cifs_rename_exit; + + rc = -EEXIST; + } /* else ... BB we could add the same check for Windows by checking the UniqueId via FILE_INTERNAL_INFO */ + + if ((rc == -EACCES) || (rc == -EEXIST)) { unlink_target: + /* don't bother if this is a negative dentry */ + if (!target_dentry->d_inode) + goto cifs_rename_exit; + + target_cinode = CIFS_I(target_dentry->d_inode); + + /* try to move the target out of the way */ + tmprc = CIFSSMBOpen(xid, tcon, toName, FILE_OPEN, DELETE, + CREATE_NOT_DIR, &dstfid, &oplock, NULL, + cifs_sb_target->local_nls, + cifs_sb_target->mnt_cifs_flags & + CIFS_MOUNT_MAP_SPECIAL_CHR); + if (tmprc) + goto cifs_rename_exit; + + /* rename the file to random name */ + tmprc = CIFSSMBRenameOpenFile(xid, tcon, dstfid, NULL, + cifs_sb_target->local_nls, + cifs_sb_target->mnt_cifs_flags & + CIFS_MOUNT_MAP_SPECIAL_CHR); + + if (tmprc) + goto close_target; + + delete_already_pending = target_cinode->delete_pending; + + if (!delete_already_pending) { + /* set delete on close */ + tmprc = CIFSSMBSetFileDisposition(xid, tcon, + true, dstfid, + current->tgid); + /* + * This hack is for broken samba servers, remove this + * once more fixed ones are in the field. + */ + if (tmprc == -ENOENT) + delete_already_pending = false; + else if (tmprc) + goto undo_target_rename; + + target_cinode->delete_pending = true; + } + + + rc = cifs_do_rename(xid, source_dentry, fromName, + target_dentry, toName); + + if (rc == 0) + goto close_target; + /* - * we either can not tell the files are hardlinked (as with - * Windows servers) or files are not hardlinked. Delete the - * target manually before renaming to follow POSIX rather than - * Windows semantics + * after this point, we can't bother with error handling on + * the undo's. This is best effort since we can't do anything + * about failures here. */ - cifs_unlink(target_inode, target_direntry); - rc = cifs_do_rename(xid, source_direntry, fromName, - target_direntry, toName); + if (!delete_already_pending) { + tmprc = CIFSSMBSetFileDisposition(xid, tcon, + false, dstfid, + current->tgid); + if (tmprc == 0) + target_cinode->delete_pending = false; + } + +undo_target_rename: + /* rename failed: undo target rename */ + CIFSSMBRenameOpenFile(xid, tcon, dstfid, + target_dentry->d_name.name, + cifs_sb_target->local_nls, + cifs_sb_target->mnt_cifs_flags & + CIFS_MOUNT_MAP_SPECIAL_CHR); +close_target: + CIFSSMBClose(xid, tcon, dstfid); } cifs_rename_exit: -- cgit v1.2.3 From a364bc0b37f14ffd66c1f982af42990a9d77fa43 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Tue, 21 Oct 2008 14:42:13 +0000 Subject: [CIFS] fix saving of resume key before CIFSFindNext We recently fixed the cifs readdir code so that it saves the resume key before calling CIFSFindNext. Unfortunately, this assumes that we have just done a CIFSFindFirst (or FindNext) and have resume info to save. This isn't necessarily the case. Fix the code to save resume info if we had to reinitiate the search, and after a FindNext. This fixes connectathon basic test6 against NetApp filers. Signed-off-by: Jeff Layton CC: Stable Signed-off-by: Steve French --- fs/cifs/readdir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index 765adf12d54..58d57299f2a 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c @@ -762,14 +762,15 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon, rc)); return rc; } + cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile); } while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) && (rc == 0) && !cifsFile->srch_inf.endOfSearch) { cFYI(1, ("calling findnext2")); - cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile); rc = CIFSFindNext(xid, pTcon, cifsFile->netfid, &cifsFile->srch_inf); + cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile); if (rc) return -ENOENT; } -- cgit v1.2.3 From 84210e9120a8c01a14379ba1f9a9b0f963641d94 Mon Sep 17 00:00:00 2001 From: Steve French Date: Thu, 23 Oct 2008 04:42:37 +0000 Subject: [CIFS] improve setlease handling fcntl(F_SETLEASE) currently is not exported by cifs (nor by local file systems) so cifs grants leases based on how other local processes have opened the file not by whether the file is cacheable (oplocked). This adds the check to make sure that the file is cacheable on the client before checking whether we can grant the lease locally (generic_setlease). It also adds a mount option for cifs (locallease) if the user wants to override this and try to grant leases even if the server did not grant oplock. Signed-off-by: Steve French --- fs/cifs/CHANGES | 3 ++- fs/cifs/README | 16 ++++++++++++++++ fs/cifs/cifsfs.c | 41 +++++++++++++++++++++++++++++++++++++++++ fs/cifs/cifsglob.h | 1 + fs/cifs/connect.c | 8 +++++++- 5 files changed, 67 insertions(+), 2 deletions(-) (limited to 'fs') diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES index a7255751ffb..8f528ea24c4 100644 --- a/fs/cifs/CHANGES +++ b/fs/cifs/CHANGES @@ -3,7 +3,8 @@ Version 1.55 Various fixes to make delete of open files behavior more predictable (when delete of an open file fails we mark the file as "delete-on-close" in a way that more servers accept, but only if we can first rename the -file to a temporary name) +file to a temporary name). Add experimental support for more safely +handling fcntl(F_SETLEASE). Version 1.54 ------------ diff --git a/fs/cifs/README b/fs/cifs/README index cbe26fe4012..a439dc1739b 100644 --- a/fs/cifs/README +++ b/fs/cifs/README @@ -491,6 +491,19 @@ A partial list of the supported mount options follows: Note that this differs from the sign mount option in that it causes encryption of data sent over this mounted share but other shares mounted to the same server are unaffected. + locallease This option is rarely needed. Fcntl F_SETLEASE is + used by some applications such as Samba and NFSv4 server to + check to see whether a file is cacheable. CIFS has no way + to explicitly request a lease, but can check whether a file + is cacheable (oplocked). Unfortunately, even if a file + is not oplocked, it could still be cacheable (ie cifs client + could grant fcntl leases if no other local processes are using + the file) for cases for example such as when the server does not + support oplocks and the user is sure that the only updates to + the file will be from this client. Specifying this mount option + will allow the cifs client to check for leases (only) locally + for files which are not oplocked instead of denying leases + in that case. (EXPERIMENTAL) sec Security mode. Allowed values are: none attempt to connection as a null user (no name) krb5 Use Kerberos version 5 authentication @@ -641,6 +654,9 @@ requires enabling CONFIG_CIFS_EXPERIMENTAL cifsacl support needed to retrieve approximated mode bits based on the contents on the CIFS ACL. + lease support: cifs will check the oplock state before calling into + the vfs to see if we can grant a lease on a file. + DNOTIFY fcntl: needed for support of directory change notification and perhaps later for file leases) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index c6aad775dd6..76919c25acc 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -618,6 +618,37 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin) return generic_file_llseek_unlocked(file, offset, origin); } +#ifdef CONFIG_CIFS_EXPERIMENTAL +static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) +{ + /* note that this is called by vfs setlease with the BKL held + although I doubt that BKL is needed here in cifs */ + struct inode *inode = file->f_path.dentry->d_inode; + + if (!(S_ISREG(inode->i_mode))) + return -EINVAL; + + /* check if file is oplocked */ + if (((arg == F_RDLCK) && + (CIFS_I(inode)->clientCanCacheRead)) || + ((arg == F_WRLCK) && + (CIFS_I(inode)->clientCanCacheAll))) + return generic_setlease(file, arg, lease); + else if (CIFS_SB(inode->i_sb)->tcon->local_lease && + !CIFS_I(inode)->clientCanCacheRead) + /* If the server claims to support oplock on this + file, then we still need to check oplock even + if the local_lease mount option is set, but there + are servers which do not support oplock for which + this mount option may be useful if the user + knows that the file won't be changed on the server + by anyone else */ + return generic_setlease(file, arg, lease); + else + return -EAGAIN; +} +#endif + struct file_system_type cifs_fs_type = { .owner = THIS_MODULE, .name = "cifs", @@ -696,6 +727,7 @@ const struct file_operations cifs_file_ops = { #ifdef CONFIG_CIFS_EXPERIMENTAL .dir_notify = cifs_dir_notify, + .setlease = cifs_setlease, #endif /* CONFIG_CIFS_EXPERIMENTAL */ }; @@ -716,6 +748,7 @@ const struct file_operations cifs_file_direct_ops = { .llseek = cifs_llseek, #ifdef CONFIG_CIFS_EXPERIMENTAL .dir_notify = cifs_dir_notify, + .setlease = cifs_setlease, #endif /* CONFIG_CIFS_EXPERIMENTAL */ }; const struct file_operations cifs_file_nobrl_ops = { @@ -736,6 +769,7 @@ const struct file_operations cifs_file_nobrl_ops = { #ifdef CONFIG_CIFS_EXPERIMENTAL .dir_notify = cifs_dir_notify, + .setlease = cifs_setlease, #endif /* CONFIG_CIFS_EXPERIMENTAL */ }; @@ -755,6 +789,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .llseek = cifs_llseek, #ifdef CONFIG_CIFS_EXPERIMENTAL .dir_notify = cifs_dir_notify, + .setlease = cifs_setlease, #endif /* CONFIG_CIFS_EXPERIMENTAL */ }; @@ -946,6 +981,12 @@ static int cifs_oplock_thread(void *dummyarg) the call */ /* mutex_lock(&inode->i_mutex);*/ if (S_ISREG(inode->i_mode)) { +#ifdef CONFIG_CIFS_EXPERIMENTAL + if (CIFS_I(inode)->clientCanCacheAll == 0) + break_lease(inode, FMODE_READ); + else if (CIFS_I(inode)->clientCanCacheRead == 0) + break_lease(inode, FMODE_WRITE); +#endif rc = filemap_fdatawrite(inode->i_mapping); if (CIFS_I(inode)->clientCanCacheRead == 0) { waitrc = filemap_fdatawait( diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 178f733a368..c791e5b5a91 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -285,6 +285,7 @@ struct cifsTconInfo { bool seal:1; /* transport encryption for this mounted share */ bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol for this mount even if server would support */ + bool local_lease:1; /* check leases (only) on local system not remote */ /* BB add field for back pointer to sb struct(s)? */ }; diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 1126f7ab460..f51b79a67e1 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -90,7 +90,8 @@ struct smb_vol { bool nocase:1; /* request case insensitive filenames */ bool nobrl:1; /* disable sending byte range locks to srv */ bool seal:1; /* request transport encryption on share */ - bool nodfs:1; + bool nodfs:1; /* Do not request DFS, even if available */ + bool local_lease:1; /* check leases only on local system, not remote */ unsigned int rsize; unsigned int wsize; unsigned int sockopt; @@ -1264,6 +1265,10 @@ cifs_parse_mount_options(char *options, const char *devname, vol->no_psx_acl = 0; } else if (strnicmp(data, "noacl", 5) == 0) { vol->no_psx_acl = 1; +#ifdef CONFIG_CIFS_EXPERIMENTAL + } else if (strnicmp(data, "locallease", 6) == 0) { + vol->local_lease = 1; +#endif } else if (strnicmp(data, "sign", 4) == 0) { vol->secFlg |= CIFSSEC_MUST_SIGN; } else if (strnicmp(data, "seal", 4) == 0) { @@ -2162,6 +2167,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, for the retry flag is used */ tcon->retry = volume_info.retry; tcon->nocase = volume_info.nocase; + tcon->local_lease = volume_info.local_lease; if (tcon->seal != volume_info.seal) cERROR(1, ("transport encryption setting " "conflicts with existing tid")); -- cgit v1.2.3 From 8d281efb67463fe8aac8f6e10b31492fc218bf2b Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 22 Oct 2008 13:57:01 -0400 Subject: cifs: fix unlinking of rename target when server doesn't support open file renames cifs: fix unlinking of rename target when server doesn't support open file renames The patch to make cifs_rename undoable broke renaming one file on top of another when the server doesn't support busy file renames. Remove the code that uses busy file renames to unlink the target file, and just have it call cifs_unlink. If the rename of the source file fails, then the unlink won't be undoable, but hopefully that's rare enough that it won't be a problem. Signed-off-by: Jeff Layton Signed-off-by: Steve French --- fs/cifs/inode.c | 87 ++++++--------------------------------------------------- 1 file changed, 8 insertions(+), 79 deletions(-) (limited to 'fs') diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 8ac4eabc1f8..d54fa8aeaea 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -1293,12 +1293,9 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, struct cifs_sb_info *cifs_sb_source; struct cifs_sb_info *cifs_sb_target; struct cifsTconInfo *tcon; - struct cifsInodeInfo *target_cinode; FILE_UNIX_BASIC_INFO *info_buf_source = NULL; FILE_UNIX_BASIC_INFO *info_buf_target; - __u16 dstfid; - int xid, rc, tmprc, oplock = 0; - bool delete_already_pending; + int xid, rc, tmprc; cifs_sb_target = CIFS_SB(target_dir->i_sb); cifs_sb_source = CIFS_SB(source_dir->i_sb); @@ -1348,104 +1345,36 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, } info_buf_target = info_buf_source + 1; - rc = CIFSSMBUnixQPathInfo(xid, tcon, fromName, + tmprc = CIFSSMBUnixQPathInfo(xid, tcon, fromName, info_buf_source, cifs_sb_source->local_nls, cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); - if (rc != 0) + if (tmprc != 0) goto unlink_target; - rc = CIFSSMBUnixQPathInfo(xid, tcon, + tmprc = CIFSSMBUnixQPathInfo(xid, tcon, toName, info_buf_target, cifs_sb_target->local_nls, /* remap based on source sb */ cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); - if (rc == 0 && (info_buf_source->UniqueId == - info_buf_target->UniqueId)) + if (tmprc == 0 && (info_buf_source->UniqueId == + info_buf_target->UniqueId)) /* same file, POSIX says that this is a noop */ goto cifs_rename_exit; - - rc = -EEXIST; } /* else ... BB we could add the same check for Windows by checking the UniqueId via FILE_INTERNAL_INFO */ - if ((rc == -EACCES) || (rc == -EEXIST)) { unlink_target: - /* don't bother if this is a negative dentry */ - if (!target_dentry->d_inode) - goto cifs_rename_exit; - - target_cinode = CIFS_I(target_dentry->d_inode); - - /* try to move the target out of the way */ - tmprc = CIFSSMBOpen(xid, tcon, toName, FILE_OPEN, DELETE, - CREATE_NOT_DIR, &dstfid, &oplock, NULL, - cifs_sb_target->local_nls, - cifs_sb_target->mnt_cifs_flags & - CIFS_MOUNT_MAP_SPECIAL_CHR); + if ((rc == -EACCES) || (rc == -EEXIST)) { + tmprc = cifs_unlink(target_dir, target_dentry); if (tmprc) goto cifs_rename_exit; - /* rename the file to random name */ - tmprc = CIFSSMBRenameOpenFile(xid, tcon, dstfid, NULL, - cifs_sb_target->local_nls, - cifs_sb_target->mnt_cifs_flags & - CIFS_MOUNT_MAP_SPECIAL_CHR); - - if (tmprc) - goto close_target; - - delete_already_pending = target_cinode->delete_pending; - - if (!delete_already_pending) { - /* set delete on close */ - tmprc = CIFSSMBSetFileDisposition(xid, tcon, - true, dstfid, - current->tgid); - /* - * This hack is for broken samba servers, remove this - * once more fixed ones are in the field. - */ - if (tmprc == -ENOENT) - delete_already_pending = false; - else if (tmprc) - goto undo_target_rename; - - target_cinode->delete_pending = true; - } - - rc = cifs_do_rename(xid, source_dentry, fromName, target_dentry, toName); - - if (rc == 0) - goto close_target; - - /* - * after this point, we can't bother with error handling on - * the undo's. This is best effort since we can't do anything - * about failures here. - */ - if (!delete_already_pending) { - tmprc = CIFSSMBSetFileDisposition(xid, tcon, - false, dstfid, - current->tgid); - if (tmprc == 0) - target_cinode->delete_pending = false; - } - -undo_target_rename: - /* rename failed: undo target rename */ - CIFSSMBRenameOpenFile(xid, tcon, dstfid, - target_dentry->d_name.name, - cifs_sb_target->local_nls, - cifs_sb_target->mnt_cifs_flags & - CIFS_MOUNT_MAP_SPECIAL_CHR); -close_target: - CIFSSMBClose(xid, tcon, dstfid); } cifs_rename_exit: -- cgit v1.2.3 From b1c8d2b421376bc941823ee93e36cb491609b02c Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 22 Oct 2008 13:57:07 -0400 Subject: cifs: handle the TCP_Server_Info->tsk field more carefully cifs: handle the TCP_Server_Info->tsk field more carefully We currently handle the TCP_Server_Info->tsk field without any locking, but with some half-measures to try and prevent races. These aren't really sufficient though. When taking down cifsd, use xchg() to swap the contents of the tsk field with NULL so we don't end up trying to send it more than one signal. Also, don't allow cifsd to exit until the signal is received if we expect one. Signed-off-by: Jeff Layton Signed-off-by: Steve French --- fs/cifs/connect.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'fs') diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index f51b79a67e1..71b7661e226 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -750,6 +750,7 @@ multi_t2_fnd: write_unlock(&GlobalSMBSeslock); kfree(server->hostname); + task_to_wake = xchg(&server->tsk, NULL); kfree(server); length = atomic_dec_return(&tcpSesAllocCount); @@ -757,6 +758,16 @@ multi_t2_fnd: mempool_resize(cifs_req_poolp, length + cifs_min_rcv, GFP_KERNEL); + /* if server->tsk was NULL then wait for a signal before exiting */ + if (!task_to_wake) { + set_current_state(TASK_INTERRUPTIBLE); + while (!signal_pending(current)) { + schedule(); + set_current_state(TASK_INTERRUPTIBLE); + } + set_current_state(TASK_RUNNING); + } + return 0; } @@ -1846,6 +1857,16 @@ convert_delimiter(char *path, char delim) } } +static void +kill_cifsd(struct TCP_Server_Info *server) +{ + struct task_struct *task; + + task = xchg(&server->tsk, NULL); + if (task) + force_sig(SIGKILL, task); +} + int cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, char *mount_data, const char *devname) @@ -2233,7 +2254,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, spin_lock(&GlobalMid_Lock); srvTcp->tcpStatus = CifsExiting; spin_unlock(&GlobalMid_Lock); - force_sig(SIGKILL, srvTcp->tsk); + kill_cifsd(srvTcp); } /* If find_unc succeeded then rc == 0 so we can not end */ if (tcon) /* up accidently freeing someone elses tcon struct */ @@ -2246,19 +2267,15 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, temp_rc = CIFSSMBLogoff(xid, pSesInfo); /* if the socketUseCount is now zero */ if ((temp_rc == -ESHUTDOWN) && - (pSesInfo->server) && - (pSesInfo->server->tsk)) - force_sig(SIGKILL, - pSesInfo->server->tsk); + (pSesInfo->server)) + kill_cifsd(pSesInfo->server); } else { cFYI(1, ("No session or bad tcon")); - if ((pSesInfo->server) && - (pSesInfo->server->tsk)) { + if (pSesInfo->server) { spin_lock(&GlobalMid_Lock); srvTcp->tcpStatus = CifsExiting; spin_unlock(&GlobalMid_Lock); - force_sig(SIGKILL, - pSesInfo->server->tsk); + kill_cifsd(pSesInfo->server); } } sesInfoFree(pSesInfo); @@ -3545,7 +3562,6 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb) int rc = 0; int xid; struct cifsSesInfo *ses = NULL; - struct task_struct *cifsd_task; char *tmp; xid = GetXid(); @@ -3561,7 +3577,6 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb) tconInfoFree(cifs_sb->tcon); if ((ses) && (ses->server)) { /* save off task so we do not refer to ses later */ - cifsd_task = ses->server->tsk; cFYI(1, ("About to do SMBLogoff ")); rc = CIFSSMBLogoff(xid, ses); if (rc == -EBUSY) { @@ -3569,8 +3584,8 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb) return 0; } else if (rc == -ESHUTDOWN) { cFYI(1, ("Waking up socket by sending signal")); - if (cifsd_task) - force_sig(SIGKILL, cifsd_task); + if (ses->server) + kill_cifsd(ses->server); rc = 0; } /* else - we have an smb session left on this socket do not kill cifsd */ -- cgit v1.2.3