fid.c (478ba09edc1f2f2ee27180a06150cb2d1a686f9c) | fid.c (6636b6dcc3db2258cd0585b8078c1c225c4b6dde) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * V9FS FID Management 4 * 5 * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net> 6 * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com> 7 */ 8 --- 14 unchanged lines hidden (view full) --- 23 * v9fs_fid_add - add a fid to a dentry 24 * @dentry: dentry that the fid is being added to 25 * @fid: fid to add 26 * 27 */ 28 29static inline void __add_fid(struct dentry *dentry, struct p9_fid *fid) 30{ | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * V9FS FID Management 4 * 5 * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net> 6 * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com> 7 */ 8 --- 14 unchanged lines hidden (view full) --- 23 * v9fs_fid_add - add a fid to a dentry 24 * @dentry: dentry that the fid is being added to 25 * @fid: fid to add 26 * 27 */ 28 29static inline void __add_fid(struct dentry *dentry, struct p9_fid *fid) 30{ |
31 atomic_set(&fid->count, 1); |
|
31 hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata); 32} 33 34void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) 35{ 36 spin_lock(&dentry->d_lock); 37 __add_fid(dentry, fid); 38 spin_unlock(&dentry->d_lock); --- 16 unchanged lines hidden (view full) --- 55 spin_lock(&inode->i_lock); 56 h = (struct hlist_head *)&inode->i_private; 57 hlist_for_each_entry(fid, h, ilist) { 58 if (uid_eq(fid->uid, uid)) { 59 ret = fid; 60 break; 61 } 62 } | 32 hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata); 33} 34 35void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) 36{ 37 spin_lock(&dentry->d_lock); 38 __add_fid(dentry, fid); 39 spin_unlock(&dentry->d_lock); --- 16 unchanged lines hidden (view full) --- 56 spin_lock(&inode->i_lock); 57 h = (struct hlist_head *)&inode->i_private; 58 hlist_for_each_entry(fid, h, ilist) { 59 if (uid_eq(fid->uid, uid)) { 60 ret = fid; 61 break; 62 } 63 } |
64 if (ret && !IS_ERR(ret)) 65 atomic_inc(&ret->count); |
|
63 spin_unlock(&inode->i_lock); 64 return ret; 65} 66 67/** 68 * v9fs_open_fid_add - add an open fid to an inode 69 * @dentry: inode that the fid is being added to 70 * @fid: fid to add 71 * 72 */ 73 74void v9fs_open_fid_add(struct inode *inode, struct p9_fid *fid) 75{ 76 spin_lock(&inode->i_lock); | 66 spin_unlock(&inode->i_lock); 67 return ret; 68} 69 70/** 71 * v9fs_open_fid_add - add an open fid to an inode 72 * @dentry: inode that the fid is being added to 73 * @fid: fid to add 74 * 75 */ 76 77void v9fs_open_fid_add(struct inode *inode, struct p9_fid *fid) 78{ 79 spin_lock(&inode->i_lock); |
80 atomic_set(&fid->count, 1); |
|
77 hlist_add_head(&fid->ilist, (struct hlist_head *)&inode->i_private); 78 spin_unlock(&inode->i_lock); 79} 80 81 82/** 83 * v9fs_fid_find - retrieve a fid that belongs to the specified uid 84 * @dentry: dentry to look for fid in --- 16 unchanged lines hidden (view full) --- 101 102 /* we'll recheck under lock if there's anything to look in */ 103 if (!ret && dentry->d_fsdata) { 104 struct hlist_head *h = (struct hlist_head *)&dentry->d_fsdata; 105 spin_lock(&dentry->d_lock); 106 hlist_for_each_entry(fid, h, dlist) { 107 if (any || uid_eq(fid->uid, uid)) { 108 ret = fid; | 81 hlist_add_head(&fid->ilist, (struct hlist_head *)&inode->i_private); 82 spin_unlock(&inode->i_lock); 83} 84 85 86/** 87 * v9fs_fid_find - retrieve a fid that belongs to the specified uid 88 * @dentry: dentry to look for fid in --- 16 unchanged lines hidden (view full) --- 105 106 /* we'll recheck under lock if there's anything to look in */ 107 if (!ret && dentry->d_fsdata) { 108 struct hlist_head *h = (struct hlist_head *)&dentry->d_fsdata; 109 spin_lock(&dentry->d_lock); 110 hlist_for_each_entry(fid, h, dlist) { 111 if (any || uid_eq(fid->uid, uid)) { 112 ret = fid; |
113 atomic_inc(&ret->count); |
|
109 break; 110 } 111 } 112 spin_unlock(&dentry->d_lock); 113 } 114 115 return ret; 116} --- 45 unchanged lines hidden (view full) --- 162 * parent fid. We need to prevent rename when we want to 163 * look at the parent. 164 */ 165 down_read(&v9ses->rename_sem); 166 ds = dentry->d_parent; 167 fid = v9fs_fid_find(ds, uid, any); 168 if (fid) { 169 /* Found the parent fid do a lookup with that */ | 114 break; 115 } 116 } 117 spin_unlock(&dentry->d_lock); 118 } 119 120 return ret; 121} --- 45 unchanged lines hidden (view full) --- 167 * parent fid. We need to prevent rename when we want to 168 * look at the parent. 169 */ 170 down_read(&v9ses->rename_sem); 171 ds = dentry->d_parent; 172 fid = v9fs_fid_find(ds, uid, any); 173 if (fid) { 174 /* Found the parent fid do a lookup with that */ |
170 fid = p9_client_walk(fid, 1, &dentry->d_name.name, 1); | 175 struct p9_fid *ofid = fid; 176 177 fid = p9_client_walk(ofid, 1, &dentry->d_name.name, 1); 178 p9_client_clunk(ofid); |
171 goto fid_out; 172 } 173 up_read(&v9ses->rename_sem); 174 175 /* start from the root and try to do a lookup */ 176 fid = v9fs_fid_find(dentry->d_sb->s_root, uid, any); 177 if (!fid) { 178 /* the user is not attached to the fs yet */ --- 8 unchanged lines hidden (view full) --- 187 fid = p9_client_attach(v9ses->clnt, NULL, uname, uid, 188 v9ses->aname); 189 if (IS_ERR(fid)) 190 return fid; 191 192 v9fs_fid_add(dentry->d_sb->s_root, fid); 193 } 194 /* If we are root ourself just return that */ | 179 goto fid_out; 180 } 181 up_read(&v9ses->rename_sem); 182 183 /* start from the root and try to do a lookup */ 184 fid = v9fs_fid_find(dentry->d_sb->s_root, uid, any); 185 if (!fid) { 186 /* the user is not attached to the fs yet */ --- 8 unchanged lines hidden (view full) --- 195 fid = p9_client_attach(v9ses->clnt, NULL, uname, uid, 196 v9ses->aname); 197 if (IS_ERR(fid)) 198 return fid; 199 200 v9fs_fid_add(dentry->d_sb->s_root, fid); 201 } 202 /* If we are root ourself just return that */ |
195 if (dentry->d_sb->s_root == dentry) | 203 if (dentry->d_sb->s_root == dentry) { 204 atomic_inc(&fid->count); |
196 return fid; | 205 return fid; |
206 } |
|
197 /* 198 * Do a multipath walk with attached root. 199 * When walking parent we need to make sure we 200 * don't have a parallel rename happening 201 */ 202 down_read(&v9ses->rename_sem); 203 n = build_path_from_dentry(v9ses, dentry, &wnames); 204 if (n < 0) { --- 30 unchanged lines hidden (view full) --- 235 if (!IS_ERR(fid)) { 236 spin_lock(&dentry->d_lock); 237 if (d_unhashed(dentry)) { 238 spin_unlock(&dentry->d_lock); 239 p9_client_clunk(fid); 240 fid = ERR_PTR(-ENOENT); 241 } else { 242 __add_fid(dentry, fid); | 207 /* 208 * Do a multipath walk with attached root. 209 * When walking parent we need to make sure we 210 * don't have a parallel rename happening 211 */ 212 down_read(&v9ses->rename_sem); 213 n = build_path_from_dentry(v9ses, dentry, &wnames); 214 if (n < 0) { --- 30 unchanged lines hidden (view full) --- 245 if (!IS_ERR(fid)) { 246 spin_lock(&dentry->d_lock); 247 if (d_unhashed(dentry)) { 248 spin_unlock(&dentry->d_lock); 249 p9_client_clunk(fid); 250 fid = ERR_PTR(-ENOENT); 251 } else { 252 __add_fid(dentry, fid); |
253 atomic_inc(&fid->count); |
|
243 spin_unlock(&dentry->d_lock); 244 } 245 } 246err_out: 247 up_read(&v9ses->rename_sem); 248 return fid; 249} 250 --- 34 unchanged lines hidden (view full) --- 285 break; 286 } 287 return v9fs_fid_lookup_with_uid(dentry, uid, any); 288} 289 290struct p9_fid *v9fs_writeback_fid(struct dentry *dentry) 291{ 292 int err; | 254 spin_unlock(&dentry->d_lock); 255 } 256 } 257err_out: 258 up_read(&v9ses->rename_sem); 259 return fid; 260} 261 --- 34 unchanged lines hidden (view full) --- 296 break; 297 } 298 return v9fs_fid_lookup_with_uid(dentry, uid, any); 299} 300 301struct p9_fid *v9fs_writeback_fid(struct dentry *dentry) 302{ 303 int err; |
293 struct p9_fid *fid; | 304 struct p9_fid *fid, *ofid; |
294 | 305 |
295 fid = clone_fid(v9fs_fid_lookup_with_uid(dentry, GLOBAL_ROOT_UID, 0)); | 306 ofid = v9fs_fid_lookup_with_uid(dentry, GLOBAL_ROOT_UID, 0); 307 if (ofid && !IS_ERR(ofid)) 308 fid = clone_fid(ofid); |
296 if (IS_ERR(fid)) 297 goto error_out; | 309 if (IS_ERR(fid)) 310 goto error_out; |
311 p9_client_clunk(ofid); |
|
298 /* 299 * writeback fid will only be used to write back the 300 * dirty pages. We always request for the open fid in read-write 301 * mode so that a partial page write which result in page 302 * read can work. 303 */ 304 err = p9_client_open(fid, O_RDWR); 305 if (err < 0) { 306 p9_client_clunk(fid); 307 fid = ERR_PTR(err); 308 goto error_out; 309 } 310error_out: 311 return fid; 312} | 312 /* 313 * writeback fid will only be used to write back the 314 * dirty pages. We always request for the open fid in read-write 315 * mode so that a partial page write which result in page 316 * read can work. 317 */ 318 err = p9_client_open(fid, O_RDWR); 319 if (err < 0) { 320 p9_client_clunk(fid); 321 fid = ERR_PTR(err); 322 goto error_out; 323 } 324error_out: 325 return fid; 326} |