Commit 10b85801 authored by Steve French's avatar Steve French

Take rename sem (where we can do it safely) when building full paths. We don't...

Take rename sem (where we can do it safely) when building full paths. We don't try to take the rename sem in cifs_rename of course because the kernel already took it above us, and for the same reason we can not take it in lookup/revalidate, but most everywhere else we build a full path we can safely take it.
parent 99eee9a8
......@@ -165,7 +165,9 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
down(&direntry->d_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(direntry);
up(&direntry->d_sb->s_vfs_rename_sem);
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......@@ -304,7 +306,9 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode, dev_t dev
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
down(&direntry->d_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(direntry);
up(&direntry->d_sb->s_vfs_rename_sem);
if(full_path == NULL)
rc = -ENOMEM;
......@@ -355,6 +359,9 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, struct name
cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
pTcon = cifs_sb->tcon;
/* can not grab the rename sem here since it would
deadlock in the cases (beginning of sys_rename itself)
in which we already have the sb rename sem */
full_path = build_path_from_dentry(direntry);
if(full_path == NULL) {
FreeXid(xid);
......
......@@ -39,7 +39,11 @@ int cifs_directory_notify(unsigned long arg, struct file * file)
xid = GetXid();
cifs_sb = CIFS_SB(file->f_dentry->d_sb);
pTcon = cifs_sb->tcon;
down(&file->f_dentry->d_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(file->f_dentry);
up(&file->f_dentry->d_sb->s_vfs_rename_sem);
if(full_path == NULL) {
rc = -ENOMEM;
} else {
......
......@@ -80,7 +80,9 @@ cifs_open(struct inode *inode, struct file *file)
}
}
down(&inode->i_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(file->f_dentry);
up(&inode->i_sb->s_vfs_rename_sem);
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......@@ -291,7 +293,10 @@ static int cifs_reopen_file(struct inode *inode, struct file *file)
}
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_dentry);
if(full_path == NULL) {
up(&pCifsFile->fh_sem);
......
......@@ -345,7 +345,11 @@ cifs_unlink(struct inode *inode, struct dentry *direntry)
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
/* Unlink can be called from rename so we can not grab
the sem here since we deadlock otherwise */
/* down(&direntry->d_sb->s_vfs_rename_sem);*/
full_path = build_path_from_dentry(direntry);
/* up(&direntry->d_sb->s_vfs_rename_sem);*/
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......@@ -430,7 +434,9 @@ cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
down(&inode->i_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(direntry);
up(&inode->i_sb->s_vfs_rename_sem);
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......@@ -487,7 +493,9 @@ cifs_rmdir(struct inode *inode, struct dentry *direntry)
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
down(&inode->i_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(direntry);
up(&inode->i_sb->s_vfs_rename_sem);
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......@@ -536,6 +544,8 @@ cifs_rename(struct inode *source_inode, struct dentry *source_direntry,
different share. Might eventually add support for this */
}
/* 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);
toName = build_path_from_dentry(target_direntry);
if((fromName == NULL) || (toName == NULL)) {
......@@ -603,6 +613,8 @@ cifs_revalidate(struct dentry *direntry)
cifs_sb = CIFS_SB(direntry->d_sb);
/* can not safely grab the rename sem here if
rename calls revalidate since that would deadlock */
full_path = build_path_from_dentry(direntry);
if(full_path == NULL) {
FreeXid(xid);
......@@ -751,7 +763,9 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
cifs_sb = CIFS_SB(direntry->d_inode->i_sb);
pTcon = cifs_sb->tcon;
down(&direntry->d_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(direntry);
up(&direntry->d_sb->s_vfs_rename_sem);
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......
......@@ -44,10 +44,13 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,
cifs_sb_target = CIFS_SB(inode->i_sb);
pTcon = cifs_sb_target->tcon;
/* No need to check for cross device links since server will do that - BB note DFS case in future though (when we may have to check) */
/* No need to check for cross device links since server will do that
BB note DFS case in future though (when we may have to check) */
down(&inode->i_sb->s_vfs_rename_sem);
fromName = build_path_from_dentry(old_file);
toName = build_path_from_dentry(direntry);
up(&inode->i_sb->s_vfs_rename_sem);
if((fromName == NULL) || (toName == NULL)) {
rc = -ENOMEM;
goto cifs_hl_exit;
......@@ -96,7 +99,11 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
struct cifsTconInfo *pTcon;
xid = GetXid();
down(&direntry->d_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(direntry);
up(&direntry->d_sb->s_vfs_rename_sem);
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......@@ -159,7 +166,10 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
down(&inode->i_sb->s_vfs_rename_sem);
full_path = build_path_from_dentry(direntry);
up(&inode->i_sb->s_vfs_rename_sem);
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......@@ -219,7 +229,13 @@ cifs_readlink(struct dentry *direntry, char *pBuffer, int buflen)
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
/* BB would it be safe against deadlock to grab this sem
even though rename itself grabs the sem and calls lookup? */
/* down(&inode->i_sb->s_vfs_rename_sem);*/
full_path = build_path_from_dentry(direntry);
/* up(&inode->i_sb->s_vfs_rename_sem);*/
if(full_path == NULL) {
FreeXid(xid);
return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment