GIT 5268df2ead6def933ace27ab4d46f67d2989b905 git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6.git commit Author: Steve French Date: Fri Apr 6 19:28:16 2007 +0000 [CIFS] Add write perm for usr to file on windows should remove r/o dos attr Remove read only dos attribute on chmod when adding any write permission (ie on any of user/group/other (not all of user/group/other ie 0222) when mounted to windows. Suggested by: Urs Fleisch Signed-off-by: Urs Fleisch Signed-off-by: Steve French commit 3a9f462f6d07ab6f26a347120e173e945139befd Author: Steve French Date: Wed Apr 4 17:10:24 2007 +0000 [CIFS] Remove unnecessary parm to cifs_reopen_file Also expand debug entry to show which character on a failed Unicode mapping. Acked-by: Shaggy Signed-off-by: Steve French commit aaf737adb6937339494d5a7111f0433cd9676db8 Author: Igor Mammedov Date: Tue Apr 3 19:16:43 2007 +0000 [CIFS] Switch cifsd to kthread_run from kernel_thread cifsd was the only cifs thread that had not been switched to the newer kthread interface Signed-off-by: Igor Mammedov Signed-off-by: Wilhelm Meier Signed-off-by: Steve French commit c33f8d32746db12ba353b0a05b25f7893a0ac344 Author: Christoph Hellwig Date: Mon Apr 2 18:47:20 2007 +0000 [CIFS] Remove unnecessary checks file->f_path.dentry or file->f_path.dentry.d_inode can't be NULL since at least ten years, similar for all but very few arguments passed in from the VFS. Signed-off-by: Christoph Hellwig Signed-off-by: Steve French fs/cifs/CHANGES | 5 ++ fs/cifs/cifs_unicode.c | 4 +- fs/cifs/cifsfs.c | 3 - fs/cifs/connect.c | 32 +++++++------ fs/cifs/file.c | 115 ++++++++++++------------------------------------ fs/cifs/inode.c | 22 +++++---- fs/cifs/readdir.c | 27 +---------- 7 files changed, 65 insertions(+), 143 deletions(-) diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES index 5d1f487..f75bdc6 100644 --- a/fs/cifs/CHANGES +++ b/fs/cifs/CHANGES @@ -9,7 +9,10 @@ from read-only back to read-write, refle (we had been leaving a file's mode read-only until the inode were reloaded). Allow setting of attribute back to ATTR_NORMAL (removing readonly dos attribute when archive dos attribute not set and we are changing mode back to writeable -on server which does not support the Unix Extensions). +on server which does not support the Unix Extensions). Remove read only dos +attribute on chmod when adding any write permission (ie on any of +user/group/other (not all of user/group/other ie 0222) when +mounted to windows. Version 1.47 ------------ diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index d2a8b29..793c4b9 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c @@ -74,8 +74,8 @@ cifs_strtoUCS(__le16 * to, const char *f charlen = codepage->char2uni(from, len, &wchar_to[i]); if (charlen < 1) { cERROR(1, - ("cifs_strtoUCS: char2uni returned %d", - charlen)); + ("strtoUCS: char2uni of %d returned %d", + (int)*from, charlen)); /* A question mark */ to[i] = cpu_to_le16(0x003f); charlen = 1; diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index faba4d6..dd03e68 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -529,8 +529,7 @@ static loff_t cifs_llseek(struct file *f /* some applications poll for the file length in this strange way so we must seek to end on non-oplocked files by setting the revalidate time to zero */ - if(file->f_path.dentry->d_inode) - CIFS_I(file->f_path.dentry->d_inode)->time = 0; + CIFS_I(file->f_path.dentry->d_inode)->time = 0; retval = cifs_revalidate(file->f_path.dentry); if (retval < 0) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 20ba7dc..9e41f8e 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -30,6 +30,7 @@ #include #include #include #include +#include #include #include #include @@ -120,7 +121,7 @@ cifs_reconnect(struct TCP_Server_Info *s struct mid_q_entry * mid_entry; spin_lock(&GlobalMid_Lock); - if(server->tcpStatus == CifsExiting) { + if( kthread_should_stop() ) { /* the demux thread will exit normally next time through the loop */ spin_unlock(&GlobalMid_Lock); @@ -182,7 +183,7 @@ cifs_reconnect(struct TCP_Server_Info *s spin_unlock(&GlobalMid_Lock); up(&server->tcpSem); - while ((server->tcpStatus != CifsExiting) && (server->tcpStatus != CifsGood)) + while ( (!kthread_should_stop()) && (server->tcpStatus != CifsGood)) { try_to_freeze(); if(server->protocolType == IPV6) { @@ -199,7 +200,7 @@ cifs_reconnect(struct TCP_Server_Info *s } else { atomic_inc(&tcpSesReconnectCount); spin_lock(&GlobalMid_Lock); - if(server->tcpStatus != CifsExiting) + if( !kthread_should_stop() ) server->tcpStatus = CifsGood; server->sequence_number = 0; spin_unlock(&GlobalMid_Lock); @@ -345,7 +346,6 @@ cifs_demultiplex_thread(struct TCP_Serve int isMultiRsp; int reconnect; - daemonize("cifsd"); allow_signal(SIGKILL); current->flags |= PF_MEMALLOC; server->tsk = current; /* save process info to wake at shutdown */ @@ -361,7 +361,7 @@ cifs_demultiplex_thread(struct TCP_Serve GFP_KERNEL); } - while (server->tcpStatus != CifsExiting) { + while (!kthread_should_stop()) { if (try_to_freeze()) continue; if (bigbuf == NULL) { @@ -400,7 +400,7 @@ cifs_demultiplex_thread(struct TCP_Serve kernel_recvmsg(csocket, &smb_msg, &iov, 1, 4, 0 /* BB see socket.h flags */); - if (server->tcpStatus == CifsExiting) { + if ( kthread_should_stop() ) { break; } else if (server->tcpStatus == CifsNeedReconnect) { cFYI(1, ("Reconnect after server stopped responding")); @@ -524,7 +524,7 @@ cifs_demultiplex_thread(struct TCP_Serve total_read += length) { length = kernel_recvmsg(csocket, &smb_msg, &iov, 1, pdu_length - total_read, 0); - if((server->tcpStatus == CifsExiting) || + if( kthread_should_stop() || (length == -EINTR)) { /* then will exit */ reconnect = 2; @@ -757,7 +757,6 @@ #endif /* CIFS_DEBUG2 */ GFP_KERNEL); } - complete_and_exit(&cifsd_complete, 0); return 0; } @@ -1850,10 +1849,11 @@ cifs_mount(struct super_block *sb, struc so no need to spinlock this init of tcpStatus */ srvTcp->tcpStatus = CifsNew; init_MUTEX(&srvTcp->tcpSem); - rc = (int)kernel_thread((void *)(void *)cifs_demultiplex_thread, srvTcp, - CLONE_FS | CLONE_FILES | CLONE_VM); - if(rc < 0) { - rc = -ENOMEM; + srvTcp->tsk = kthread_run((void *)(void *)cifs_demultiplex_thread, srvTcp, "cifsd"); + if( IS_ERR(srvTcp->tsk) ) { + rc = PTR_ERR(srvTcp->tsk); + cERROR(1,("error %d create cifsd thread", rc)); + srvTcp->tsk = NULL; sock_release(csocket); kfree(volume_info.UNC); kfree(volume_info.password); @@ -2050,7 +2050,7 @@ cifs_mount(struct super_block *sb, struc spin_unlock(&GlobalMid_Lock); if(srvTcp->tsk) { send_sig(SIGKILL,srvTcp->tsk,1); - wait_for_completion(&cifsd_complete); + kthread_stop(srvTcp->tsk); } } /* If find_unc succeeded then rc == 0 so we can not end */ @@ -2064,9 +2064,9 @@ cifs_mount(struct super_block *sb, struc temp_rc = CIFSSMBLogoff(xid, pSesInfo); /* if the socketUseCount is now zero */ if((temp_rc == -ESHUTDOWN) && - (pSesInfo->server->tsk)) { + (pSesInfo->server) && (pSesInfo->server->tsk)) { send_sig(SIGKILL,pSesInfo->server->tsk,1); - wait_for_completion(&cifsd_complete); + kthread_stop(pSesInfo->server->tsk); } } else cFYI(1, ("No session or bad tcon")); @@ -3316,7 +3316,7 @@ cifs_umount(struct super_block *sb, stru cFYI(1,("Waking up socket by sending it signal")); if(cifsd_task) { send_sig(SIGKILL,cifsd_task,1); - wait_for_completion(&cifsd_complete); + kthread_stop(cifsd_task); } rc = 0; } /* else - we have an smb session diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 2d3275b..467cf89 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -338,8 +338,7 @@ static int cifs_relock_file(struct cifsF return rc; } -static int cifs_reopen_file(struct inode *inode, struct file *file, - int can_flush) +static int cifs_reopen_file(struct file *file, int can_flush) { int rc = -EACCES; int xid, oplock; @@ -347,13 +346,12 @@ static int cifs_reopen_file(struct inode struct cifsTconInfo *pTcon; struct cifsFileInfo *pCifsFile; struct cifsInodeInfo *pCifsInode; + struct inode * inode; char *full_path = NULL; int desiredAccess; int disposition = FILE_OPEN; __u16 netfid; - if (inode == NULL) - return -EBADF; if (file->private_data) { pCifsFile = (struct cifsFileInfo *)file->private_data; } else @@ -368,25 +366,37 @@ static int cifs_reopen_file(struct inode } if (file->f_path.dentry == NULL) { - up(&pCifsFile->fh_sem); - cFYI(1, ("failed file reopen, no valid name if dentry freed")); - FreeXid(xid); - return -EBADF; + cERROR(1, ("no valid name if dentry freed")); + dump_stack(); + rc = -EBADF; + goto reopen_error_exit; } + + inode = file->f_path.dentry->d_inode; + if(inode == NULL) { + cERROR(1, ("inode not valid")); + dump_stack(); + rc = -EBADF; + goto reopen_error_exit; + } + cifs_sb = CIFS_SB(inode->i_sb); pTcon = cifs_sb->tcon; + /* can not grab rename sem here because various ops, including those that already have the rename sem can end up causing writepage to get called and if the server was down that means we end up here, and we can never tell if the caller already has the rename_sem */ full_path = build_path_from_dentry(file->f_path.dentry); if (full_path == NULL) { + rc = -ENOMEM; +reopen_error_exit: up(&pCifsFile->fh_sem); FreeXid(xid); - return -ENOMEM; + return rc; } - cFYI(1, (" inode = 0x%p file flags are 0x%x for %s", + cFYI(1, ("inode = 0x%p file flags 0x%x for %s", inode, file->f_flags,full_path)); desiredAccess = cifs_convert_flags(file->f_flags); @@ -401,13 +411,6 @@ static int cifs_reopen_file(struct inode and server version of file size can be stale. If we knew for sure that inode was not dirty locally we could do this */ -/* buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); - if (buf == 0) { - up(&pCifsFile->fh_sem); - kfree(full_path); - FreeXid(xid); - return -ENOMEM; - } */ rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, NULL, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & @@ -792,12 +795,7 @@ ssize_t cifs_user_write(struct file *fil int xid, long_op; struct cifsFileInfo *open_file; - if (file->f_path.dentry == NULL) - return -EBADF; - cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); - if (cifs_sb == NULL) - return -EBADF; pTcon = cifs_sb->tcon; @@ -807,14 +805,9 @@ ssize_t cifs_user_write(struct file *fil if (file->private_data == NULL) return -EBADF; - else - open_file = (struct cifsFileInfo *) file->private_data; + open_file = (struct cifsFileInfo *) file->private_data; xid = GetXid(); - if (file->f_path.dentry->d_inode == NULL) { - FreeXid(xid); - return -EBADF; - } if (*poffset > file->f_path.dentry->d_inode->i_size) long_op = 2; /* writes past end of file can take a long time */ @@ -841,17 +834,11 @@ ssize_t cifs_user_write(struct file *fil return -EBADF; } if (open_file->invalidHandle) { - if ((file->f_path.dentry == NULL) || - (file->f_path.dentry->d_inode == NULL)) { - FreeXid(xid); - return total_written; - } /* we could deadlock if we called filemap_fdatawait from here so tell reopen_file not to flush data to server now */ - rc = cifs_reopen_file(file->f_path.dentry->d_inode, - file, FALSE); + rc = cifs_reopen_file(file, FALSE); if (rc != 0) break; } @@ -908,12 +895,7 @@ static ssize_t cifs_write(struct file *f int xid, long_op; struct cifsFileInfo *open_file; - if (file->f_path.dentry == NULL) - return -EBADF; - cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); - if (cifs_sb == NULL) - return -EBADF; pTcon = cifs_sb->tcon; @@ -922,14 +904,9 @@ static ssize_t cifs_write(struct file *f if (file->private_data == NULL) return -EBADF; - else - open_file = (struct cifsFileInfo *)file->private_data; + open_file = (struct cifsFileInfo *)file->private_data; xid = GetXid(); - if (file->f_path.dentry->d_inode == NULL) { - FreeXid(xid); - return -EBADF; - } if (*poffset > file->f_path.dentry->d_inode->i_size) long_op = 2; /* writes past end of file can take a long time */ @@ -957,17 +934,11 @@ static ssize_t cifs_write(struct file *f return -EBADF; } if (open_file->invalidHandle) { - if ((file->f_path.dentry == NULL) || - (file->f_path.dentry->d_inode == NULL)) { - FreeXid(xid); - return total_written; - } /* we could deadlock if we called filemap_fdatawait from here so tell reopen_file not to flush data to server now */ - rc = cifs_reopen_file(file->f_path.dentry->d_inode, - file, FALSE); + rc = cifs_reopen_file(file, FALSE); if (rc != 0) break; } @@ -1056,8 +1027,7 @@ struct cifsFileInfo *find_writable_file( read_unlock(&GlobalSMBSeslock); if((open_file->invalidHandle) && (!open_file->closePend) /* BB fixme -since the second clause can not be true remove it BB */) { - rc = cifs_reopen_file(&cifs_inode->vfs_inode, - open_file->pfile, FALSE); + rc = cifs_reopen_file(open_file->pfile, FALSE); /* if it fails, try another handle - might be */ /* dangerous to hold up writepages with retry */ if(rc) { @@ -1404,32 +1374,6 @@ static int cifs_commit_write(struct file spin_lock(&inode->i_lock); if (position > inode->i_size) { i_size_write(inode, position); - /* if (file->private_data == NULL) { - rc = -EBADF; - } else { - open_file = (struct cifsFileInfo *)file->private_data; - cifs_sb = CIFS_SB(inode->i_sb); - rc = -EAGAIN; - while (rc == -EAGAIN) { - if ((open_file->invalidHandle) && - (!open_file->closePend)) { - rc = cifs_reopen_file( - file->f_path.dentry->d_inode, file); - if (rc != 0) - break; - } - if (!open_file->closePend) { - rc = CIFSSMBSetFileSize(xid, - cifs_sb->tcon, position, - open_file->netfid, - open_file->pid, FALSE); - } else { - rc = -EBADF; - break; - } - } - cFYI(1, (" SetEOF (commit write) rc = %d", rc)); - } */ } spin_unlock(&inode->i_lock); if (!PageUptodate(page)) { @@ -1573,8 +1517,7 @@ ssize_t cifs_user_read(struct file *file int buf_type = CIFS_NO_BUFFER; if ((open_file->invalidHandle) && (!open_file->closePend)) { - rc = cifs_reopen_file(file->f_path.dentry->d_inode, - file, TRUE); + rc = cifs_reopen_file(file, TRUE); if (rc != 0) break; } @@ -1660,8 +1603,7 @@ static ssize_t cifs_read(struct file *fi while (rc == -EAGAIN) { if ((open_file->invalidHandle) && (!open_file->closePend)) { - rc = cifs_reopen_file(file->f_path.dentry->d_inode, - file, TRUE); + rc = cifs_reopen_file(file, TRUE); if (rc != 0) break; } @@ -1817,8 +1759,7 @@ static int cifs_readpages(struct file *f while (rc == -EAGAIN) { if ((open_file->invalidHandle) && (!open_file->closePend)) { - rc = cifs_reopen_file(file->f_path.dentry->d_inode, - file, TRUE); + rc = cifs_reopen_file(file, TRUE); if (rc != 0) break; } diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index f414526..eeea337 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -1339,17 +1339,17 @@ int cifs_setattr(struct dentry *direntry cpu_to_le32(cifsInode->cifsAttrs | ATTR_READONLY); } - } else if ((mode & S_IWUGO) == S_IWUGO) { - if (cifsInode->cifsAttrs & ATTR_READONLY) { - set_dosattr = TRUE; - time_buf.Attributes = - cpu_to_le32(cifsInode->cifsAttrs & - (~ATTR_READONLY)); - /* Windows ignores set to zero */ - if(time_buf.Attributes == 0) - time_buf.Attributes |= - cpu_to_le32(ATTR_NORMAL); - } + } else if (cifsInode->cifsAttrs & ATTR_READONLY) { + /* If file is readonly on server, we would + not be able to write to it - so if any write + bit is enabled for user or group or other we + need to at least try to remove r/o dos attr */ + set_dosattr = TRUE; + time_buf.Attributes = cpu_to_le32(cifsInode->cifsAttrs & + (~ATTR_READONLY)); + /* Windows ignores set to zero */ + if(time_buf.Attributes == 0) + time_buf.Attributes |= cpu_to_le32(ATTR_NORMAL); } /* BB to be implemented - via Windows security descriptors or streams */ diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index 2a374d5..3fab8ed 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c @@ -444,9 +444,6 @@ static int initiate_cifs_search(const in cifsFile->invalidHandle = TRUE; cifsFile->srch_inf.endOfSearch = FALSE; - if(file->f_path.dentry == NULL) - return -ENOENT; - cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); if(cifs_sb == NULL) return -EINVAL; @@ -618,20 +615,10 @@ static int cifs_entry_is_dot(char *curre whether we can use the cached search results from the previous search */ static int is_dir_changed(struct file * file) { - struct inode * inode; - struct cifsInodeInfo *cifsInfo; - - if(file->f_path.dentry == NULL) - return 0; - - inode = file->f_path.dentry->d_inode; - - if(inode == NULL) - return 0; - - cifsInfo = CIFS_I(inode); + struct inode *inode = file->f_path.dentry->d_inode; + struct cifsInodeInfo *cifsInfo = CIFS_I(inode); - if(cifsInfo->time == 0) + if (cifsInfo->time == 0) return 1; /* directory was changed, perhaps due to unlink */ else return 0; @@ -851,9 +838,6 @@ static int cifs_filldir(char *pfindEntry if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL)) return -ENOENT; - if(file->f_path.dentry == NULL) - return -ENOENT; - rc = cifs_entry_is_dot(pfindEntry,pCifsF); /* skip . and .. since we added them first */ if(rc != 0) @@ -997,11 +981,6 @@ int cifs_readdir(struct file *file, void xid = GetXid(); - if(file->f_path.dentry == NULL) { - FreeXid(xid); - return -EIO; - } - cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); pTcon = cifs_sb->tcon; if(pTcon == NULL)