提交 0b8dd177 编写于 作者: L Latchesar Ionkov 提交者: Linus Torvalds

[PATCH] v9fs: fix races in fid allocation

Fid management cleanup.  The patch attempts to fix the races in dentry's
fid management.

Dentries don't keep the opened fids anymore, they are moved to the file
structs.  Ideally there should be no more than one fid with fidcreate equal
to zero in the dentry's list of fids.

v9fs_fid_create initializes the important fields (fid, fidcreated) before
v9fs_fid is added to the list.  v9fs_fid_lookup returns only fids that are
not created by v9fs_create.  v9fs_fid_get_created returns the fid created
by the same process by v9fs_create (if any) and removes it from dentry's
list
Signed-off-by: NLatchesar Ionkov <lucho@ionkov.net>
Cc: Eric Van Hensbergen <ericvh@gmail.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 dc7b5fd6
...@@ -71,21 +71,28 @@ static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry) ...@@ -71,21 +71,28 @@ static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
* *
*/ */
struct v9fs_fid *v9fs_fid_create(struct dentry *dentry) struct v9fs_fid *v9fs_fid_create(struct dentry *dentry,
struct v9fs_session_info *v9ses, int fid, int create)
{ {
struct v9fs_fid *new; struct v9fs_fid *new;
dprintk(DEBUG_9P, "fid create dentry %p, fid %d, create %d\n",
dentry, fid, create);
new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL); new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
if (new == NULL) { if (new == NULL) {
dprintk(DEBUG_ERROR, "Out of Memory\n"); dprintk(DEBUG_ERROR, "Out of Memory\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
new->fid = -1; new->fid = fid;
new->v9ses = v9ses;
new->fidopen = 0; new->fidopen = 0;
new->fidcreate = 0; new->fidcreate = create;
new->fidclunked = 0; new->fidclunked = 0;
new->iounit = 0; new->iounit = 0;
new->rdir_pos = 0;
new->rdir_fcall = NULL;
if (v9fs_fid_insert(new, dentry) == 0) if (v9fs_fid_insert(new, dentry) == 0)
return new; return new;
...@@ -108,6 +115,59 @@ void v9fs_fid_destroy(struct v9fs_fid *fid) ...@@ -108,6 +115,59 @@ void v9fs_fid_destroy(struct v9fs_fid *fid)
kfree(fid); kfree(fid);
} }
/**
* v9fs_fid_walk_up - walks from the process current directory
* up to the specified dentry.
*/
static struct v9fs_fid *v9fs_fid_walk_up(struct dentry *dentry)
{
int fidnum, cfidnum, err;
struct v9fs_fid *cfid;
struct dentry *cde;
struct v9fs_session_info *v9ses;
v9ses = v9fs_inode2v9ses(current->fs->pwd->d_inode);
cfid = v9fs_fid_lookup(current->fs->pwd);
if (cfid == NULL) {
dprintk(DEBUG_ERROR, "process cwd doesn't have a fid\n");
return ERR_PTR(-ENOENT);
}
cfidnum = cfid->fid;
cde = current->fs->pwd;
/* TODO: take advantage of multiwalk */
fidnum = v9fs_get_idpool(&v9ses->fidpool);
if (fidnum < 0) {
dprintk(DEBUG_ERROR, "could not get a new fid num\n");
err = -ENOENT;
goto clunk_fid;
}
while (cde != dentry) {
if (cde == cde->d_parent) {
dprintk(DEBUG_ERROR, "can't find dentry\n");
err = -ENOENT;
goto clunk_fid;
}
err = v9fs_t_walk(v9ses, cfidnum, fidnum, "..", NULL);
if (err < 0) {
dprintk(DEBUG_ERROR, "problem walking to parent\n");
goto clunk_fid;
}
cfidnum = fidnum;
cde = cde->d_parent;
}
return v9fs_fid_create(dentry, v9ses, fidnum, 0);
clunk_fid:
v9fs_t_clunk(v9ses, fidnum, NULL);
return ERR_PTR(err);
}
/** /**
* v9fs_fid_lookup - retrieve the right fid from a particular dentry * v9fs_fid_lookup - retrieve the right fid from a particular dentry
* @dentry: dentry to look for fid in * @dentry: dentry to look for fid in
...@@ -119,49 +179,25 @@ void v9fs_fid_destroy(struct v9fs_fid *fid) ...@@ -119,49 +179,25 @@ void v9fs_fid_destroy(struct v9fs_fid *fid)
* *
*/ */
struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type) struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
{ {
struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
struct v9fs_fid *current_fid = NULL; struct v9fs_fid *current_fid = NULL;
struct v9fs_fid *temp = NULL; struct v9fs_fid *temp = NULL;
struct v9fs_fid *return_fid = NULL; struct v9fs_fid *return_fid = NULL;
int found_parent = 0;
int found_user = 0;
dprintk(DEBUG_9P, " dentry: %s (%p) type %d\n", dentry->d_iname, dentry, dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
type);
if (fid_list && !list_empty(fid_list)) { if (fid_list) {
list_for_each_entry_safe(current_fid, temp, fid_list, list) { list_for_each_entry_safe(current_fid, temp, fid_list, list) {
if (current_fid->uid == current->uid) { if (!current_fid->fidcreate) {
if (return_fid == NULL) { return_fid = current_fid;
if ((type == FID_OP) break;
|| (!current_fid->fidopen)) {
return_fid = current_fid;
found_user = 1;
}
}
}
if (current_fid->pid == current->real_parent->pid) {
if ((return_fid == NULL) || (found_parent)
|| (found_user)) {
if ((type == FID_OP)
|| (!current_fid->fidopen)) {
return_fid = current_fid;
found_parent = 1;
found_user = 0;
}
}
}
if (current_fid->pid == current->pid) {
if ((type == FID_OP) ||
(!current_fid->fidopen)) {
return_fid = current_fid;
found_parent = 0;
found_user = 0;
}
} }
} }
if (!return_fid)
return_fid = current_fid;
} }
/* we are at the root but didn't match */ /* we are at the root but didn't match */
...@@ -187,55 +223,33 @@ struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type) ...@@ -187,55 +223,33 @@ struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type)
/* XXX - there may be some duplication we can get rid of */ /* XXX - there may be some duplication we can get rid of */
if (par == dentry) { if (par == dentry) {
/* we need to fid_lookup the starting point */ return_fid = v9fs_fid_walk_up(dentry);
int fidnum = -1; if (IS_ERR(return_fid))
int oldfid = -1; return_fid = NULL;
int result = -1; }
struct v9fs_session_info *v9ses = }
v9fs_inode2v9ses(current->fs->pwd->d_inode);
current_fid =
v9fs_fid_lookup(current->fs->pwd, FID_WALK);
if (current_fid == NULL) {
dprintk(DEBUG_ERROR,
"process cwd doesn't have a fid\n");
return return_fid;
}
oldfid = current_fid->fid;
par = current->fs->pwd;
/* TODO: take advantage of multiwalk */
fidnum = v9fs_get_idpool(&v9ses->fidpool); return return_fid;
if (fidnum < 0) { }
dprintk(DEBUG_ERROR,
"could not get a new fid num\n");
return return_fid;
}
while (par != dentry) { struct v9fs_fid *v9fs_fid_get_created(struct dentry *dentry)
result = {
v9fs_t_walk(v9ses, oldfid, fidnum, "..", struct list_head *fid_list;
NULL); struct v9fs_fid *fid, *ftmp, *ret;
if (result < 0) {
dprintk(DEBUG_ERROR, dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
"problem walking to parent\n"); fid_list = (struct list_head *)dentry->d_fsdata;
ret = NULL;
break; if (fid_list) {
} list_for_each_entry_safe(fid, ftmp, fid_list, list) {
oldfid = fidnum; if (fid->fidcreate && fid->pid == current->pid) {
if (par == par->d_parent) { list_del(&fid->list);
dprintk(DEBUG_ERROR, ret = fid;
"can't find dentry\n"); break;
break;
}
par = par->d_parent;
}
if (par == dentry) {
return_fid = v9fs_fid_create(dentry);
return_fid->fid = fidnum;
} }
} }
} }
return return_fid; dprintk(DEBUG_9P, "return %p\n", ret);
return ret;
} }
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define FID_OP 0 #define FID_OP 0
#define FID_WALK 1 #define FID_WALK 1
#define FID_CREATE 2
struct v9fs_fid { struct v9fs_fid {
struct list_head list; /* list of fids associated with a dentry */ struct list_head list; /* list of fids associated with a dentry */
...@@ -52,6 +53,8 @@ struct v9fs_fid { ...@@ -52,6 +53,8 @@ struct v9fs_fid {
struct v9fs_session_info *v9ses; /* session info for this FID */ struct v9fs_session_info *v9ses; /* session info for this FID */
}; };
struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type); struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry);
struct v9fs_fid *v9fs_fid_get_created(struct dentry *);
void v9fs_fid_destroy(struct v9fs_fid *fid); void v9fs_fid_destroy(struct v9fs_fid *fid);
struct v9fs_fid *v9fs_fid_create(struct dentry *); struct v9fs_fid *v9fs_fid_create(struct dentry *,
struct v9fs_session_info *v9ses, int fid, int create);
...@@ -67,7 +67,7 @@ static int v9fs_dentry_validate(struct dentry *dentry, struct nameidata *nd) ...@@ -67,7 +67,7 @@ static int v9fs_dentry_validate(struct dentry *dentry, struct nameidata *nd)
struct dentry *dc = current->fs->pwd; struct dentry *dc = current->fs->pwd;
dprintk(DEBUG_VFS, "dentry: %s (%p)\n", dentry->d_iname, dentry); dprintk(DEBUG_VFS, "dentry: %s (%p)\n", dentry->d_iname, dentry);
if (v9fs_fid_lookup(dentry, FID_OP)) { if (v9fs_fid_lookup(dentry)) {
dprintk(DEBUG_VFS, "VALID\n"); dprintk(DEBUG_VFS, "VALID\n");
return 1; return 1;
} }
......
...@@ -197,21 +197,18 @@ int v9fs_dir_release(struct inode *inode, struct file *filp) ...@@ -197,21 +197,18 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
filemap_fdatawait(inode->i_mapping); filemap_fdatawait(inode->i_mapping);
if (fidnum >= 0) { if (fidnum >= 0) {
fid->fidopen--;
dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen, dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen,
fid->fid); fid->fid);
if (fid->fidopen == 0) { if (v9fs_t_clunk(v9ses, fidnum, NULL))
if (v9fs_t_clunk(v9ses, fidnum, NULL)) dprintk(DEBUG_ERROR, "clunk failed\n");
dprintk(DEBUG_ERROR, "clunk failed\n");
v9fs_put_idpool(fid->fid, &v9ses->fidpool); v9fs_put_idpool(fid->fid, &v9ses->fidpool);
}
kfree(fid->rdir_fcall); kfree(fid->rdir_fcall);
kfree(fid);
filp->private_data = NULL; filp->private_data = NULL;
v9fs_fid_destroy(fid);
} }
d_drop(filp->f_dentry); d_drop(filp->f_dentry);
......
...@@ -53,30 +53,36 @@ ...@@ -53,30 +53,36 @@
int v9fs_file_open(struct inode *inode, struct file *file) int v9fs_file_open(struct inode *inode, struct file *file)
{ {
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
struct v9fs_fid *v9fid = v9fs_fid_lookup(file->f_dentry, FID_WALK); struct v9fs_fid *v9fid, *fid;
struct v9fs_fid *v9newfid = NULL;
struct v9fs_fcall *fcall = NULL; struct v9fs_fcall *fcall = NULL;
int open_mode = 0; int open_mode = 0;
unsigned int iounit = 0; unsigned int iounit = 0;
int newfid = -1; int newfid = -1;
long result = -1; long result = -1;
dprintk(DEBUG_VFS, "inode: %p file: %p v9fid= %p\n", inode, file, dprintk(DEBUG_VFS, "inode: %p file: %p \n", inode, file);
v9fid);
v9fid = v9fs_fid_get_created(file->f_dentry);
if (!v9fid)
v9fid = v9fs_fid_lookup(file->f_dentry);
if (!v9fid) { if (!v9fid) {
struct dentry *dentry = file->f_dentry;
dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n"); dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n");
return -EBADF;
}
/* XXX - some duplication from lookup, generalize later */ if (!v9fid->fidcreate) {
/* basically vfs_lookup is too heavy weight */ fid = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
v9fid = v9fs_fid_lookup(file->f_dentry, FID_OP); if (fid == NULL) {
if (!v9fid) dprintk(DEBUG_ERROR, "Out of Memory\n");
return -EBADF; return -ENOMEM;
}
v9fid = v9fs_fid_lookup(dentry->d_parent, FID_WALK); fid->fidopen = 0;
if (!v9fid) fid->fidcreate = 0;
return -EBADF; fid->fidclunked = 0;
fid->iounit = 0;
fid->v9ses = v9ses;
newfid = v9fs_get_idpool(&v9ses->fidpool); newfid = v9fs_get_idpool(&v9ses->fidpool);
if (newfid < 0) { if (newfid < 0) {
...@@ -85,58 +91,16 @@ int v9fs_file_open(struct inode *inode, struct file *file) ...@@ -85,58 +91,16 @@ int v9fs_file_open(struct inode *inode, struct file *file)
} }
result = result =
v9fs_t_walk(v9ses, v9fid->fid, newfid, v9fs_t_walk(v9ses, v9fid->fid, newfid, NULL, NULL);
(char *)file->f_dentry->d_name.name, NULL);
if (result < 0) { if (result < 0) {
v9fs_put_idpool(newfid, &v9ses->fidpool); v9fs_put_idpool(newfid, &v9ses->fidpool);
dprintk(DEBUG_ERROR, "rewalk didn't work\n"); dprintk(DEBUG_ERROR, "rewalk didn't work\n");
return -EBADF; return -EBADF;
} }
v9fid = v9fs_fid_create(dentry); fid->fid = newfid;
if (v9fid == NULL) { v9fid = fid;
dprintk(DEBUG_ERROR, "couldn't insert\n");
return -ENOMEM;
}
v9fid->fid = newfid;
}
if (v9fid->fidcreate) {
/* create case */
newfid = v9fid->fid;
iounit = v9fid->iounit;
v9fid->fidcreate = 0;
} else {
if (!S_ISDIR(inode->i_mode))
newfid = v9fid->fid;
else {
newfid = v9fs_get_idpool(&v9ses->fidpool);
if (newfid < 0) {
eprintk(KERN_WARNING, "allocation failed\n");
return -ENOSPC;
}
/* This would be a somewhat critical clone */
result =
v9fs_t_walk(v9ses, v9fid->fid, newfid, NULL,
&fcall);
if (result < 0) {
dprintk(DEBUG_ERROR, "clone error: %s\n",
FCALL_ERROR(fcall));
kfree(fcall);
return result;
}
v9newfid = v9fs_fid_create(file->f_dentry);
v9newfid->fid = newfid;
v9newfid->qid = v9fid->qid;
v9newfid->iounit = v9fid->iounit;
v9newfid->fidopen = 0;
v9newfid->fidclunked = 0;
v9newfid->v9ses = v9ses;
v9fid = v9newfid;
kfree(fcall);
}
/* TODO: do special things for O_EXCL, O_NOFOLLOW, O_SYNC */ /* TODO: do special things for O_EXCL, O_NOFOLLOW, O_SYNC */
/* translate open mode appropriately */ /* translate open mode appropriately */
open_mode = file->f_flags & 0x3; open_mode = file->f_flags & 0x3;
...@@ -163,9 +127,13 @@ int v9fs_file_open(struct inode *inode, struct file *file) ...@@ -163,9 +127,13 @@ int v9fs_file_open(struct inode *inode, struct file *file)
iounit = fcall->params.ropen.iounit; iounit = fcall->params.ropen.iounit;
kfree(fcall); kfree(fcall);
} else {
/* create case */
newfid = v9fid->fid;
iounit = v9fid->iounit;
v9fid->fidcreate = 0;
} }
file->private_data = v9fid; file->private_data = v9fid;
v9fid->rdir_pos = 0; v9fid->rdir_pos = 0;
......
...@@ -307,7 +307,7 @@ v9fs_create(struct inode *dir, ...@@ -307,7 +307,7 @@ v9fs_create(struct inode *dir,
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct v9fs_fid *dirfid = struct v9fs_fid *dirfid =
v9fs_fid_lookup(file_dentry->d_parent, FID_WALK); v9fs_fid_lookup(file_dentry->d_parent);
struct v9fs_fid *fid = NULL; struct v9fs_fid *fid = NULL;
struct inode *file_inode = NULL; struct inode *file_inode = NULL;
struct v9fs_fcall *fcall = NULL; struct v9fs_fcall *fcall = NULL;
...@@ -317,6 +317,7 @@ v9fs_create(struct inode *dir, ...@@ -317,6 +317,7 @@ v9fs_create(struct inode *dir,
long newfid = -1; long newfid = -1;
int result = 0; int result = 0;
unsigned int iounit = 0; unsigned int iounit = 0;
int wfidno = -1;
perm = unixmode2p9mode(v9ses, perm); perm = unixmode2p9mode(v9ses, perm);
...@@ -350,7 +351,7 @@ v9fs_create(struct inode *dir, ...@@ -350,7 +351,7 @@ v9fs_create(struct inode *dir,
if (result < 0) { if (result < 0) {
dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall)); dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall));
v9fs_put_idpool(newfid, &v9ses->fidpool); v9fs_put_idpool(newfid, &v9ses->fidpool);
newfid = 0; newfid = -1;
goto CleanUpFid; goto CleanUpFid;
} }
...@@ -369,20 +370,39 @@ v9fs_create(struct inode *dir, ...@@ -369,20 +370,39 @@ v9fs_create(struct inode *dir,
qid = fcall->params.rcreate.qid; qid = fcall->params.rcreate.qid;
kfree(fcall); kfree(fcall);
fid = v9fs_fid_create(file_dentry); fid = v9fs_fid_create(file_dentry, v9ses, newfid, 1);
dprintk(DEBUG_VFS, "fid %p %d\n", fid, fid->fidcreate);
if (!fid) { if (!fid) {
result = -ENOMEM; result = -ENOMEM;
goto CleanUpFid; goto CleanUpFid;
} }
fid->fid = newfid;
fid->fidopen = 0;
fid->fidcreate = 1;
fid->qid = qid; fid->qid = qid;
fid->iounit = iounit; fid->iounit = iounit;
fid->rdir_pos = 0;
fid->rdir_fcall = NULL; /* walk to the newly created file and put the fid in the dentry */
fid->v9ses = v9ses; wfidno = v9fs_get_idpool(&v9ses->fidpool);
if (newfid < 0) {
eprintk(KERN_WARNING, "no free fids available\n");
return -ENOSPC;
}
result = v9fs_t_walk(v9ses, dirfidnum, wfidno,
(char *) file_dentry->d_name.name, NULL);
if (result < 0) {
dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall));
v9fs_put_idpool(wfidno, &v9ses->fidpool);
wfidno = -1;
goto CleanUpFid;
}
if (!v9fs_fid_create(file_dentry, v9ses, wfidno, 0)) {
if (!v9fs_t_clunk(v9ses, newfid, &fcall)) {
v9fs_put_idpool(wfidno, &v9ses->fidpool);
}
goto CleanUpFid;
}
if ((perm & V9FS_DMSYMLINK) || (perm & V9FS_DMLINK) || if ((perm & V9FS_DMSYMLINK) || (perm & V9FS_DMLINK) ||
(perm & V9FS_DMNAMEDPIPE) || (perm & V9FS_DMSOCKET) || (perm & V9FS_DMNAMEDPIPE) || (perm & V9FS_DMSOCKET) ||
...@@ -410,11 +430,11 @@ v9fs_create(struct inode *dir, ...@@ -410,11 +430,11 @@ v9fs_create(struct inode *dir,
d_instantiate(file_dentry, file_inode); d_instantiate(file_dentry, file_inode);
if (perm & V9FS_DMDIR) { if (perm & V9FS_DMDIR) {
if (v9fs_t_clunk(v9ses, newfid, &fcall)) if (!v9fs_t_clunk(v9ses, newfid, &fcall))
v9fs_put_idpool(newfid, &v9ses->fidpool);
else
dprintk(DEBUG_ERROR, "clunk for mkdir failed: %s\n", dprintk(DEBUG_ERROR, "clunk for mkdir failed: %s\n",
FCALL_ERROR(fcall)); FCALL_ERROR(fcall));
v9fs_put_idpool(newfid, &v9ses->fidpool);
kfree(fcall); kfree(fcall);
fid->fidopen = 0; fid->fidopen = 0;
fid->fidcreate = 0; fid->fidcreate = 0;
...@@ -426,12 +446,22 @@ v9fs_create(struct inode *dir, ...@@ -426,12 +446,22 @@ v9fs_create(struct inode *dir,
CleanUpFid: CleanUpFid:
kfree(fcall); kfree(fcall);
if (newfid) { if (newfid >= 0) {
if (v9fs_t_clunk(v9ses, newfid, &fcall)) if (!v9fs_t_clunk(v9ses, newfid, &fcall))
v9fs_put_idpool(newfid, &v9ses->fidpool);
else
dprintk(DEBUG_ERROR, "clunk failed: %s\n",
FCALL_ERROR(fcall));
kfree(fcall);
}
if (wfidno >= 0) {
if (!v9fs_t_clunk(v9ses, wfidno, &fcall))
v9fs_put_idpool(wfidno, &v9ses->fidpool);
else
dprintk(DEBUG_ERROR, "clunk failed: %s\n", dprintk(DEBUG_ERROR, "clunk failed: %s\n",
FCALL_ERROR(fcall)); FCALL_ERROR(fcall));
v9fs_put_idpool(newfid, &v9ses->fidpool);
kfree(fcall); kfree(fcall);
} }
return result; return result;
...@@ -461,7 +491,7 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) ...@@ -461,7 +491,7 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
file_inode = file->d_inode; file_inode = file->d_inode;
sb = file_inode->i_sb; sb = file_inode->i_sb;
v9ses = v9fs_inode2v9ses(file_inode); v9ses = v9fs_inode2v9ses(file_inode);
v9fid = v9fs_fid_lookup(file, FID_OP); v9fid = v9fs_fid_lookup(file);
if (!v9fid) { if (!v9fid) {
dprintk(DEBUG_ERROR, dprintk(DEBUG_ERROR,
...@@ -545,7 +575,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -545,7 +575,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
sb = dir->i_sb; sb = dir->i_sb;
v9ses = v9fs_inode2v9ses(dir); v9ses = v9fs_inode2v9ses(dir);
dirfid = v9fs_fid_lookup(dentry->d_parent, FID_WALK); dirfid = v9fs_fid_lookup(dentry->d_parent);
if (!dirfid) { if (!dirfid) {
dprintk(DEBUG_ERROR, "no dirfid\n"); dprintk(DEBUG_ERROR, "no dirfid\n");
...@@ -573,7 +603,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -573,7 +603,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
v9fs_put_idpool(newfid, &v9ses->fidpool); v9fs_put_idpool(newfid, &v9ses->fidpool);
if (result == -ENOENT) { if (result == -ENOENT) {
d_add(dentry, NULL); d_add(dentry, NULL);
dprintk(DEBUG_ERROR, dprintk(DEBUG_VFS,
"Return negative dentry %p count %d\n", "Return negative dentry %p count %d\n",
dentry, atomic_read(&dentry->d_count)); dentry, atomic_read(&dentry->d_count));
return NULL; return NULL;
...@@ -601,16 +631,13 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -601,16 +631,13 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat->qid); inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat->qid);
fid = v9fs_fid_create(dentry); fid = v9fs_fid_create(dentry, v9ses, newfid, 0);
if (fid == NULL) { if (fid == NULL) {
dprintk(DEBUG_ERROR, "couldn't insert\n"); dprintk(DEBUG_ERROR, "couldn't insert\n");
result = -ENOMEM; result = -ENOMEM;
goto FreeFcall; goto FreeFcall;
} }
fid->fid = newfid;
fid->fidopen = 0;
fid->v9ses = v9ses;
fid->qid = fcall->params.rstat.stat->qid; fid->qid = fcall->params.rstat.stat->qid;
dentry->d_op = &v9fs_dentry_operations; dentry->d_op = &v9fs_dentry_operations;
...@@ -665,11 +692,11 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -665,11 +692,11 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
{ {
struct inode *old_inode = old_dentry->d_inode; struct inode *old_inode = old_dentry->d_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode);
struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_WALK); struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
struct v9fs_fid *olddirfid = struct v9fs_fid *olddirfid =
v9fs_fid_lookup(old_dentry->d_parent, FID_WALK); v9fs_fid_lookup(old_dentry->d_parent);
struct v9fs_fid *newdirfid = struct v9fs_fid *newdirfid =
v9fs_fid_lookup(new_dentry->d_parent, FID_WALK); v9fs_fid_lookup(new_dentry->d_parent);
struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
struct v9fs_fcall *fcall = NULL; struct v9fs_fcall *fcall = NULL;
int fid = -1; int fid = -1;
...@@ -744,7 +771,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -744,7 +771,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
{ {
struct v9fs_fcall *fcall = NULL; struct v9fs_fcall *fcall = NULL;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP); struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
int err = -EPERM; int err = -EPERM;
dprintk(DEBUG_VFS, "dentry: %p\n", dentry); dprintk(DEBUG_VFS, "dentry: %p\n", dentry);
...@@ -778,7 +805,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -778,7 +805,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
{ {
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP); struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
struct v9fs_fcall *fcall = NULL; struct v9fs_fcall *fcall = NULL;
struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
int res = -EPERM; int res = -EPERM;
...@@ -960,7 +987,7 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) ...@@ -960,7 +987,7 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
if (retval != 0) if (retval != 0)
goto FreeFcall; goto FreeFcall;
newfid = v9fs_fid_lookup(dentry, FID_OP); newfid = v9fs_fid_lookup(dentry);
/* issue a twstat */ /* issue a twstat */
v9fs_blank_mistat(v9ses, mistat); v9fs_blank_mistat(v9ses, mistat);
...@@ -1004,7 +1031,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) ...@@ -1004,7 +1031,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
struct v9fs_fcall *fcall = NULL; struct v9fs_fcall *fcall = NULL;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP); struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
if (!fid) { if (!fid) {
dprintk(DEBUG_ERROR, "could not resolve fid from dentry\n"); dprintk(DEBUG_ERROR, "could not resolve fid from dentry\n");
...@@ -1148,7 +1175,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1148,7 +1175,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
struct v9fs_fcall *fcall = NULL; struct v9fs_fcall *fcall = NULL;
struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_OP); struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
struct v9fs_fid *newfid = NULL; struct v9fs_fid *newfid = NULL;
char *symname = __getname(); char *symname = __getname();
...@@ -1168,7 +1195,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1168,7 +1195,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
if (retval != 0) if (retval != 0)
goto FreeMem; goto FreeMem;
newfid = v9fs_fid_lookup(dentry, FID_OP); newfid = v9fs_fid_lookup(dentry);
if (!newfid) { if (!newfid) {
dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n"); dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n");
goto FreeMem; goto FreeMem;
...@@ -1246,7 +1273,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) ...@@ -1246,7 +1273,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
if (retval != 0) if (retval != 0)
goto FreeMem; goto FreeMem;
newfid = v9fs_fid_lookup(dentry, FID_OP); newfid = v9fs_fid_lookup(dentry);
if (!newfid) { if (!newfid) {
dprintk(DEBUG_ERROR, "coudn't resove fid from dentry\n"); dprintk(DEBUG_ERROR, "coudn't resove fid from dentry\n");
retval = -EINVAL; retval = -EINVAL;
......
...@@ -129,8 +129,7 @@ static struct super_block *v9fs_get_sb(struct file_system_type ...@@ -129,8 +129,7 @@ static struct super_block *v9fs_get_sb(struct file_system_type
if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) { if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) {
dprintk(DEBUG_ERROR, "problem initiating session\n"); dprintk(DEBUG_ERROR, "problem initiating session\n");
kfree(v9ses); return newfid;
return ERR_PTR(newfid);
} }
sb = sget(fs_type, NULL, v9fs_set_super, v9ses); sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
...@@ -155,23 +154,19 @@ static struct super_block *v9fs_get_sb(struct file_system_type ...@@ -155,23 +154,19 @@ static struct super_block *v9fs_get_sb(struct file_system_type
sb->s_root = root; sb->s_root = root;
/* Setup the Root Inode */
root_fid = v9fs_fid_create(root);
if (root_fid == NULL) {
retval = -ENOMEM;
goto put_back_sb;
}
root_fid->fidopen = 0;
root_fid->v9ses = v9ses;
stat_result = v9fs_t_stat(v9ses, newfid, &fcall); stat_result = v9fs_t_stat(v9ses, newfid, &fcall);
if (stat_result < 0) { if (stat_result < 0) {
dprintk(DEBUG_ERROR, "stat error\n"); dprintk(DEBUG_ERROR, "stat error\n");
v9fs_t_clunk(v9ses, newfid, NULL); v9fs_t_clunk(v9ses, newfid, NULL);
v9fs_put_idpool(newfid, &v9ses->fidpool); v9fs_put_idpool(newfid, &v9ses->fidpool);
} else { } else {
root_fid->fid = newfid; /* Setup the Root Inode */
root_fid = v9fs_fid_create(root, v9ses, newfid, 0);
if (root_fid == NULL) {
retval = -ENOMEM;
goto put_back_sb;
}
root_fid->qid = fcall->params.rstat.stat->qid; root_fid->qid = fcall->params.rstat.stat->qid;
root->d_inode->i_ino = root->d_inode->i_ino =
v9fs_qid2ino(&fcall->params.rstat.stat->qid); v9fs_qid2ino(&fcall->params.rstat.stat->qid);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册