aboutsummaryrefslogtreecommitdiffstats
path: root/fs/9p/fid.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/9p/fid.c')
-rw-r--r--fs/9p/fid.c145
1 files changed, 12 insertions, 133 deletions
diff --git a/fs/9p/fid.c b/fs/9p/fid.c
index eda449778fa5..c4d13bf904d2 100644
--- a/fs/9p/fid.c
+++ b/fs/9p/fid.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * V9FS FID Management 2 * V9FS FID Management
3 * 3 *
4 * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com> 4 * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@
40 * 40 *
41 */ 41 */
42 42
43static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry) 43int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
44{ 44{
45 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; 45 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
46 dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid, 46 dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
@@ -57,7 +57,6 @@ static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
57 } 57 }
58 58
59 fid->uid = current->uid; 59 fid->uid = current->uid;
60 fid->pid = current->pid;
61 list_add(&fid->list, fid_list); 60 list_add(&fid->list, fid_list);
62 return 0; 61 return 0;
63} 62}
@@ -68,14 +67,11 @@ static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
68 * 67 *
69 */ 68 */
70 69
71struct v9fs_fid *v9fs_fid_create(struct dentry *dentry, 70struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid)
72 struct v9fs_session_info *v9ses, int fid, int create)
73{ 71{
74 struct v9fs_fid *new; 72 struct v9fs_fid *new;
75 73
76 dprintk(DEBUG_9P, "fid create dentry %p, fid %d, create %d\n", 74 dprintk(DEBUG_9P, "fid create fid %d\n", fid);
77 dentry, fid, create);
78
79 new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL); 75 new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
80 if (new == NULL) { 76 if (new == NULL) {
81 dprintk(DEBUG_ERROR, "Out of Memory\n"); 77 dprintk(DEBUG_ERROR, "Out of Memory\n");
@@ -85,19 +81,13 @@ struct v9fs_fid *v9fs_fid_create(struct dentry *dentry,
85 new->fid = fid; 81 new->fid = fid;
86 new->v9ses = v9ses; 82 new->v9ses = v9ses;
87 new->fidopen = 0; 83 new->fidopen = 0;
88 new->fidcreate = create;
89 new->fidclunked = 0; 84 new->fidclunked = 0;
90 new->iounit = 0; 85 new->iounit = 0;
91 new->rdir_pos = 0; 86 new->rdir_pos = 0;
92 new->rdir_fcall = NULL; 87 new->rdir_fcall = NULL;
88 INIT_LIST_HEAD(&new->list);
93 89
94 if (v9fs_fid_insert(new, dentry) == 0) 90 return new;
95 return new;
96 else {
97 dprintk(DEBUG_ERROR, "Problems inserting to dentry\n");
98 kfree(new);
99 return NULL;
100 }
101} 91}
102 92
103/** 93/**
@@ -113,140 +103,29 @@ void v9fs_fid_destroy(struct v9fs_fid *fid)
113} 103}
114 104
115/** 105/**
116 * v9fs_fid_walk_up - walks from the process current directory
117 * up to the specified dentry.
118 */
119static struct v9fs_fid *v9fs_fid_walk_up(struct dentry *dentry)
120{
121 int fidnum, cfidnum, err;
122 struct v9fs_fid *cfid;
123 struct dentry *cde;
124 struct v9fs_session_info *v9ses;
125
126 v9ses = v9fs_inode2v9ses(current->fs->pwd->d_inode);
127 cfid = v9fs_fid_lookup(current->fs->pwd);
128 if (cfid == NULL) {
129 dprintk(DEBUG_ERROR, "process cwd doesn't have a fid\n");
130 return ERR_PTR(-ENOENT);
131 }
132
133 cfidnum = cfid->fid;
134 cde = current->fs->pwd;
135 /* TODO: take advantage of multiwalk */
136
137 fidnum = v9fs_get_idpool(&v9ses->fidpool);
138 if (fidnum < 0) {
139 dprintk(DEBUG_ERROR, "could not get a new fid num\n");
140 err = -ENOENT;
141 goto clunk_fid;
142 }
143
144 while (cde != dentry) {
145 if (cde == cde->d_parent) {
146 dprintk(DEBUG_ERROR, "can't find dentry\n");
147 err = -ENOENT;
148 goto clunk_fid;
149 }
150
151 err = v9fs_t_walk(v9ses, cfidnum, fidnum, "..", NULL);
152 if (err < 0) {
153 dprintk(DEBUG_ERROR, "problem walking to parent\n");
154 goto clunk_fid;
155 }
156
157 cfidnum = fidnum;
158 cde = cde->d_parent;
159 }
160
161 return v9fs_fid_create(dentry, v9ses, fidnum, 0);
162
163clunk_fid:
164 v9fs_t_clunk(v9ses, fidnum);
165 return ERR_PTR(err);
166}
167
168/**
169 * v9fs_fid_lookup - retrieve the right fid from a particular dentry 106 * v9fs_fid_lookup - retrieve the right fid from a particular dentry
170 * @dentry: dentry to look for fid in 107 * @dentry: dentry to look for fid in
171 * @type: intent of lookup (operation or traversal) 108 * @type: intent of lookup (operation or traversal)
172 * 109 *
173 * search list of fids associated with a dentry for a fid with a matching 110 * find a fid in the dentry
174 * thread id or uid. If that fails, look up the dentry's parents to see if you 111 *
175 * can find a matching fid. 112 * TODO: only match fids that have the same uid as current user
176 * 113 *
177 */ 114 */
178 115
179struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry) 116struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
180{ 117{
181 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; 118 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
182 struct v9fs_fid *current_fid = NULL;
183 struct v9fs_fid *temp = NULL;
184 struct v9fs_fid *return_fid = NULL; 119 struct v9fs_fid *return_fid = NULL;
185 120
186 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry); 121 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
187 122
188 if (fid_list) { 123 if (fid_list)
189 list_for_each_entry_safe(current_fid, temp, fid_list, list) { 124 return_fid = list_entry(fid_list->next, struct v9fs_fid, list);
190 if (!current_fid->fidcreate) {
191 return_fid = current_fid;
192 break;
193 }
194 }
195
196 if (!return_fid)
197 return_fid = current_fid;
198 }
199
200 /* we are at the root but didn't match */
201 if ((!return_fid) && (dentry->d_parent == dentry)) {
202 /* TODO: clone attach with new uid */
203 return_fid = current_fid;
204 }
205 125
206 if (!return_fid) { 126 if (!return_fid) {
207 struct dentry *par = current->fs->pwd->d_parent; 127 dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n");
208 int count = 1;
209 while (par != NULL) {
210 if (par == dentry)
211 break;
212 count++;
213 if (par == par->d_parent) {
214 dprintk(DEBUG_ERROR,
215 "got to root without finding dentry\n");
216 break;
217 }
218 par = par->d_parent;
219 }
220
221/* XXX - there may be some duplication we can get rid of */
222 if (par == dentry) {
223 return_fid = v9fs_fid_walk_up(dentry);
224 if (IS_ERR(return_fid))
225 return_fid = NULL;
226 }
227 } 128 }
228 129
229 return return_fid; 130 return return_fid;
230} 131}
231
232struct v9fs_fid *v9fs_fid_get_created(struct dentry *dentry)
233{
234 struct list_head *fid_list;
235 struct v9fs_fid *fid, *ftmp, *ret;
236
237 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
238 fid_list = (struct list_head *)dentry->d_fsdata;
239 ret = NULL;
240 if (fid_list) {
241 list_for_each_entry_safe(fid, ftmp, fid_list, list) {
242 if (fid->fidcreate && fid->pid == current->pid) {
243 list_del(&fid->list);
244 ret = fid;
245 break;
246 }
247 }
248 }
249
250 dprintk(DEBUG_9P, "return %p\n", ret);
251 return ret;
252}