Diff markup
1 /* dir.c: AFS filesystem directory handling 1 /* dir.c: AFS filesystem directory handling
2 * 2 *
3 * Copyright (C) 2002 Red Hat, Inc. All Rights 3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.c 4 * Written by David Howells (dhowells@redhat.com)
5 * 5 *
6 * This program is free software; you can redi 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Genera 7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundatio 8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any l 9 * 2 of the License, or (at your option) any later version.
10 */ 10 */
11 11
12 #include <linux/kernel.h> 12 #include <linux/kernel.h>
13 #include <linux/module.h> 13 #include <linux/module.h>
14 #include <linux/init.h> 14 #include <linux/init.h>
15 #include <linux/slab.h> 15 #include <linux/slab.h>
16 #include <linux/fs.h> 16 #include <linux/fs.h>
17 #include <linux/pagemap.h> 17 #include <linux/pagemap.h>
18 #include <linux/ctype.h> 18 #include <linux/ctype.h>
19 #include <linux/sched.h> 19 #include <linux/sched.h>
20 #include "internal.h" 20 #include "internal.h"
21 21
22 static struct dentry *afs_lookup(struct inode 22 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
23 struct nameid 23 struct nameidata *nd);
24 static int afs_dir_open(struct inode *inode, s 24 static int afs_dir_open(struct inode *inode, struct file *file);
25 static int afs_readdir(struct file *file, void 25 static int afs_readdir(struct file *file, void *dirent, filldir_t filldir);
26 static int afs_d_revalidate(struct dentry *den 26 static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd);
27 static int afs_d_delete(struct dentry *dentry) 27 static int afs_d_delete(struct dentry *dentry);
28 static void afs_d_release(struct dentry *dentr 28 static void afs_d_release(struct dentry *dentry);
29 static int afs_lookup_filldir(void *_cookie, c 29 static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
30 loff_t fpos, 30 loff_t fpos, u64 ino, unsigned dtype);
31 static int afs_create(struct inode *dir, struc 31 static int afs_create(struct inode *dir, struct dentry *dentry, int mode,
32 struct nameidata *nd); 32 struct nameidata *nd);
33 static int afs_mkdir(struct inode *dir, struct 33 static int afs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
34 static int afs_rmdir(struct inode *dir, struct 34 static int afs_rmdir(struct inode *dir, struct dentry *dentry);
35 static int afs_unlink(struct inode *dir, struc 35 static int afs_unlink(struct inode *dir, struct dentry *dentry);
36 static int afs_link(struct dentry *from, struc 36 static int afs_link(struct dentry *from, struct inode *dir,
37 struct dentry *dentry); 37 struct dentry *dentry);
38 static int afs_symlink(struct inode *dir, stru 38 static int afs_symlink(struct inode *dir, struct dentry *dentry,
39 const char *content); 39 const char *content);
40 static int afs_rename(struct inode *old_dir, s 40 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
41 struct inode *new_dir, s 41 struct inode *new_dir, struct dentry *new_dentry);
42 42
43 const struct file_operations afs_dir_file_oper 43 const struct file_operations afs_dir_file_operations = {
44 .open = afs_dir_open, 44 .open = afs_dir_open,
45 .release = afs_release, 45 .release = afs_release,
46 .readdir = afs_readdir, 46 .readdir = afs_readdir,
47 .lock = afs_lock, 47 .lock = afs_lock,
>> 48 .llseek = generic_file_llseek,
48 }; 49 };
49 50
50 const struct inode_operations afs_dir_inode_op 51 const struct inode_operations afs_dir_inode_operations = {
51 .create = afs_create, 52 .create = afs_create,
52 .lookup = afs_lookup, 53 .lookup = afs_lookup,
53 .link = afs_link, 54 .link = afs_link,
54 .unlink = afs_unlink, 55 .unlink = afs_unlink,
55 .symlink = afs_symlink, 56 .symlink = afs_symlink,
56 .mkdir = afs_mkdir, 57 .mkdir = afs_mkdir,
57 .rmdir = afs_rmdir, 58 .rmdir = afs_rmdir,
58 .rename = afs_rename, 59 .rename = afs_rename,
59 .permission = afs_permission, 60 .permission = afs_permission,
60 .getattr = afs_getattr, 61 .getattr = afs_getattr,
61 .setattr = afs_setattr, 62 .setattr = afs_setattr,
62 }; 63 };
63 64
64 static struct dentry_operations afs_fs_dentry_ !! 65 static const struct dentry_operations afs_fs_dentry_operations = {
65 .d_revalidate = afs_d_revalidate, 66 .d_revalidate = afs_d_revalidate,
66 .d_delete = afs_d_delete, 67 .d_delete = afs_d_delete,
67 .d_release = afs_d_release, 68 .d_release = afs_d_release,
68 }; 69 };
69 70
70 #define AFS_DIR_HASHTBL_SIZE 128 71 #define AFS_DIR_HASHTBL_SIZE 128
71 #define AFS_DIR_DIRENT_SIZE 32 72 #define AFS_DIR_DIRENT_SIZE 32
72 #define AFS_DIRENT_PER_BLOCK 64 73 #define AFS_DIRENT_PER_BLOCK 64
73 74
74 union afs_dirent { 75 union afs_dirent {
75 struct { 76 struct {
76 uint8_t valid; 77 uint8_t valid;
77 uint8_t unused[1]; 78 uint8_t unused[1];
78 __be16 hash_next; 79 __be16 hash_next;
79 __be32 vnode; 80 __be32 vnode;
80 __be32 unique; 81 __be32 unique;
81 uint8_t name[16]; 82 uint8_t name[16];
82 uint8_t overflow[4]; 83 uint8_t overflow[4]; /* if any char of the name (inc
83 84 * NUL) reaches here, consume
84 85 * the next dirent too */
85 } u; 86 } u;
86 uint8_t extended_name[32]; 87 uint8_t extended_name[32];
87 }; 88 };
88 89
89 /* AFS directory page header (one at the begin 90 /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
90 struct afs_dir_pagehdr { 91 struct afs_dir_pagehdr {
91 __be16 npages; 92 __be16 npages;
92 __be16 magic; 93 __be16 magic;
93 #define AFS_DIR_MAGIC htons(1234) 94 #define AFS_DIR_MAGIC htons(1234)
94 uint8_t nentries; 95 uint8_t nentries;
95 uint8_t bitmap[8]; 96 uint8_t bitmap[8];
96 uint8_t pad[19]; 97 uint8_t pad[19];
97 }; 98 };
98 99
99 /* directory block layout */ 100 /* directory block layout */
100 union afs_dir_block { 101 union afs_dir_block {
101 102
102 struct afs_dir_pagehdr pagehdr; 103 struct afs_dir_pagehdr pagehdr;
103 104
104 struct { 105 struct {
105 struct afs_dir_pagehdr pagehd 106 struct afs_dir_pagehdr pagehdr;
106 uint8_t alloc_ 107 uint8_t alloc_ctrs[128];
107 /* dir hash table */ 108 /* dir hash table */
108 uint16_t hashta 109 uint16_t hashtable[AFS_DIR_HASHTBL_SIZE];
109 } hdr; 110 } hdr;
110 111
111 union afs_dirent dirents[AFS_DIRENT_PE 112 union afs_dirent dirents[AFS_DIRENT_PER_BLOCK];
112 }; 113 };
113 114
114 /* layout on a linux VM page */ 115 /* layout on a linux VM page */
115 struct afs_dir_page { 116 struct afs_dir_page {
116 union afs_dir_block blocks[PAGE_SIZE / 117 union afs_dir_block blocks[PAGE_SIZE / sizeof(union afs_dir_block)];
117 }; 118 };
118 119
119 struct afs_lookup_cookie { 120 struct afs_lookup_cookie {
120 struct afs_fid fid; 121 struct afs_fid fid;
121 const char *name; 122 const char *name;
122 size_t nlen; 123 size_t nlen;
123 int found; 124 int found;
124 }; 125 };
125 126
126 /* 127 /*
127 * check that a directory page is valid 128 * check that a directory page is valid
128 */ 129 */
129 static inline void afs_dir_check_page(struct i 130 static inline void afs_dir_check_page(struct inode *dir, struct page *page)
130 { 131 {
131 struct afs_dir_page *dbuf; 132 struct afs_dir_page *dbuf;
132 loff_t latter; 133 loff_t latter;
133 int tmp, qty; 134 int tmp, qty;
134 135
135 #if 0 136 #if 0
136 /* check the page count */ 137 /* check the page count */
137 qty = desc.size / sizeof(dbuf->blocks[ 138 qty = desc.size / sizeof(dbuf->blocks[0]);
138 if (qty == 0) 139 if (qty == 0)
139 goto error; 140 goto error;
140 141
141 if (page->index == 0 && qty != ntohs(d 142 if (page->index == 0 && qty != ntohs(dbuf->blocks[0].pagehdr.npages)) {
142 printk("kAFS: %s(%lu): wrong n 143 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
143 __FUNCTION__, dir->i_in !! 144 __func__, dir->i_ino, qty,
144 ntohs(dbuf->blocks[0].p 145 ntohs(dbuf->blocks[0].pagehdr.npages));
145 goto error; 146 goto error;
146 } 147 }
147 #endif 148 #endif
148 149
149 /* determine how many magic numbers th 150 /* determine how many magic numbers there should be in this page */
150 latter = dir->i_size - page_offset(pag 151 latter = dir->i_size - page_offset(page);
151 if (latter >= PAGE_SIZE) 152 if (latter >= PAGE_SIZE)
152 qty = PAGE_SIZE; 153 qty = PAGE_SIZE;
153 else 154 else
154 qty = latter; 155 qty = latter;
155 qty /= sizeof(union afs_dir_block); 156 qty /= sizeof(union afs_dir_block);
156 157
157 /* check them */ 158 /* check them */
158 dbuf = page_address(page); 159 dbuf = page_address(page);
159 for (tmp = 0; tmp < qty; tmp++) { 160 for (tmp = 0; tmp < qty; tmp++) {
160 if (dbuf->blocks[tmp].pagehdr. 161 if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) {
161 printk("kAFS: %s(%lu): 162 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
162 __FUNCTION__, d !! 163 __func__, dir->i_ino, tmp, qty,
163 ntohs(dbuf->blo 164 ntohs(dbuf->blocks[tmp].pagehdr.magic));
164 goto error; 165 goto error;
165 } 166 }
166 } 167 }
167 168
168 SetPageChecked(page); 169 SetPageChecked(page);
169 return; 170 return;
170 171
171 error: 172 error:
172 SetPageChecked(page); 173 SetPageChecked(page);
173 SetPageError(page); 174 SetPageError(page);
174 } 175 }
175 176
176 /* 177 /*
177 * discard a page cached in the pagecache 178 * discard a page cached in the pagecache
178 */ 179 */
179 static inline void afs_dir_put_page(struct pag 180 static inline void afs_dir_put_page(struct page *page)
180 { 181 {
181 kunmap(page); 182 kunmap(page);
182 page_cache_release(page); 183 page_cache_release(page);
183 } 184 }
184 185
185 /* 186 /*
186 * get a page into the pagecache 187 * get a page into the pagecache
187 */ 188 */
188 static struct page *afs_dir_get_page(struct in 189 static struct page *afs_dir_get_page(struct inode *dir, unsigned long index,
189 struct ke 190 struct key *key)
190 { 191 {
191 struct page *page; 192 struct page *page;
192 struct file file = { 193 struct file file = {
193 .private_data = key, 194 .private_data = key,
194 }; 195 };
195 196
196 _enter("{%lu},%lu", dir->i_ino, index) 197 _enter("{%lu},%lu", dir->i_ino, index);
197 198
198 page = read_mapping_page(dir->i_mappin 199 page = read_mapping_page(dir->i_mapping, index, &file);
199 if (!IS_ERR(page)) { 200 if (!IS_ERR(page)) {
200 kmap(page); 201 kmap(page);
201 if (!PageChecked(page)) 202 if (!PageChecked(page))
202 afs_dir_check_page(dir 203 afs_dir_check_page(dir, page);
203 if (PageError(page)) 204 if (PageError(page))
204 goto fail; 205 goto fail;
205 } 206 }
206 return page; 207 return page;
207 208
208 fail: 209 fail:
209 afs_dir_put_page(page); 210 afs_dir_put_page(page);
210 _leave(" = -EIO"); 211 _leave(" = -EIO");
211 return ERR_PTR(-EIO); 212 return ERR_PTR(-EIO);
212 } 213 }
213 214
214 /* 215 /*
215 * open an AFS directory file 216 * open an AFS directory file
216 */ 217 */
217 static int afs_dir_open(struct inode *inode, s 218 static int afs_dir_open(struct inode *inode, struct file *file)
218 { 219 {
219 _enter("{%lu}", inode->i_ino); 220 _enter("{%lu}", inode->i_ino);
220 221
221 BUILD_BUG_ON(sizeof(union afs_dir_bloc 222 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
222 BUILD_BUG_ON(sizeof(union afs_dirent) 223 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
223 224
224 if (test_bit(AFS_VNODE_DELETED, &AFS_F 225 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags))
225 return -ENOENT; 226 return -ENOENT;
226 227
227 return afs_open(inode, file); 228 return afs_open(inode, file);
228 } 229 }
229 230
230 /* 231 /*
231 * deal with one block in an AFS directory 232 * deal with one block in an AFS directory
232 */ 233 */
233 static int afs_dir_iterate_block(unsigned *fpo 234 static int afs_dir_iterate_block(unsigned *fpos,
234 union afs_dir 235 union afs_dir_block *block,
235 unsigned blko 236 unsigned blkoff,
236 void *cookie, 237 void *cookie,
237 filldir_t fil 238 filldir_t filldir)
238 { 239 {
239 union afs_dirent *dire; 240 union afs_dirent *dire;
240 unsigned offset, next, curr; 241 unsigned offset, next, curr;
241 size_t nlen; 242 size_t nlen;
242 int tmp, ret; 243 int tmp, ret;
243 244
244 _enter("%u,%x,%p,,",*fpos,blkoff,block 245 _enter("%u,%x,%p,,",*fpos,blkoff,block);
245 246
246 curr = (*fpos - blkoff) / sizeof(union 247 curr = (*fpos - blkoff) / sizeof(union afs_dirent);
247 248
248 /* walk through the block, an entry at 249 /* walk through the block, an entry at a time */
249 for (offset = AFS_DIRENT_PER_BLOCK - b 250 for (offset = AFS_DIRENT_PER_BLOCK - block->pagehdr.nentries;
250 offset < AFS_DIRENT_PER_BLOCK; 251 offset < AFS_DIRENT_PER_BLOCK;
251 offset = next 252 offset = next
252 ) { 253 ) {
253 next = offset + 1; 254 next = offset + 1;
254 255
255 /* skip entries marked unused 256 /* skip entries marked unused in the bitmap */
256 if (!(block->pagehdr.bitmap[of 257 if (!(block->pagehdr.bitmap[offset / 8] &
257 (1 << (offset % 8)))) { 258 (1 << (offset % 8)))) {
258 _debug("ENT[%Zu.%u]: u 259 _debug("ENT[%Zu.%u]: unused",
259 blkoff / sizeof 260 blkoff / sizeof(union afs_dir_block), offset);
260 if (offset >= curr) 261 if (offset >= curr)
261 *fpos = blkoff 262 *fpos = blkoff +
262 next * 263 next * sizeof(union afs_dirent);
263 continue; 264 continue;
264 } 265 }
265 266
266 /* got a valid entry */ 267 /* got a valid entry */
267 dire = &block->dirents[offset] 268 dire = &block->dirents[offset];
268 nlen = strnlen(dire->u.name, 269 nlen = strnlen(dire->u.name,
269 sizeof(*block) 270 sizeof(*block) -
270 offset * sizeof 271 offset * sizeof(union afs_dirent));
271 272
272 _debug("ENT[%Zu.%u]: %s %Zu \" 273 _debug("ENT[%Zu.%u]: %s %Zu \"%s\"",
273 blkoff / sizeof(union a 274 blkoff / sizeof(union afs_dir_block), offset,
274 (offset < curr ? "skip" 275 (offset < curr ? "skip" : "fill"),
275 nlen, dire->u.name); 276 nlen, dire->u.name);
276 277
277 /* work out where the next pos 278 /* work out where the next possible entry is */
278 for (tmp = nlen; tmp > 15; tmp 279 for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) {
279 if (next >= AFS_DIRENT 280 if (next >= AFS_DIRENT_PER_BLOCK) {
280 _debug("ENT[%Z 281 _debug("ENT[%Zu.%u]:"
281 " %u tr 282 " %u travelled beyond end dir block"
282 " (len 283 " (len %u/%Zu)",
283 blkoff 284 blkoff / sizeof(union afs_dir_block),
284 offset, 285 offset, next, tmp, nlen);
285 return -EIO; 286 return -EIO;
286 } 287 }
287 if (!(block->pagehdr.b 288 if (!(block->pagehdr.bitmap[next / 8] &
288 (1 << (next % 8) 289 (1 << (next % 8)))) {
289 _debug("ENT[%Z 290 _debug("ENT[%Zu.%u]:"
290 " %u un 291 " %u unmarked extension (len %u/%Zu)",
291 blkoff 292 blkoff / sizeof(union afs_dir_block),
292 offset, 293 offset, next, tmp, nlen);
293 return -EIO; 294 return -EIO;
294 } 295 }
295 296
296 _debug("ENT[%Zu.%u]: e 297 _debug("ENT[%Zu.%u]: ext %u/%Zu",
297 blkoff / sizeof 298 blkoff / sizeof(union afs_dir_block),
298 next, tmp, nlen 299 next, tmp, nlen);
299 next++; 300 next++;
300 } 301 }
301 302
302 /* skip if starts before the c 303 /* skip if starts before the current position */
303 if (offset < curr) 304 if (offset < curr)
304 continue; 305 continue;
305 306
306 /* found the next entry */ 307 /* found the next entry */
307 ret = filldir(cookie, 308 ret = filldir(cookie,
308 dire->u.name, 309 dire->u.name,
309 nlen, 310 nlen,
310 blkoff + offset 311 blkoff + offset * sizeof(union afs_dirent),
311 ntohl(dire->u.vn 312 ntohl(dire->u.vnode),
312 filldir == afs_l 313 filldir == afs_lookup_filldir ?
313 ntohl(dire->u.un 314 ntohl(dire->u.unique) : DT_UNKNOWN);
314 if (ret < 0) { 315 if (ret < 0) {
315 _leave(" = 0 [full]"); 316 _leave(" = 0 [full]");
316 return 0; 317 return 0;
317 } 318 }
318 319
319 *fpos = blkoff + next * sizeof 320 *fpos = blkoff + next * sizeof(union afs_dirent);
320 } 321 }
321 322
322 _leave(" = 1 [more]"); 323 _leave(" = 1 [more]");
323 return 1; 324 return 1;
324 } 325 }
325 326
326 /* 327 /*
327 * iterate through the data blob that lists th 328 * iterate through the data blob that lists the contents of an AFS directory
328 */ 329 */
329 static int afs_dir_iterate(struct inode *dir, 330 static int afs_dir_iterate(struct inode *dir, unsigned *fpos, void *cookie,
330 filldir_t filldir, 331 filldir_t filldir, struct key *key)
331 { 332 {
332 union afs_dir_block *dblock; 333 union afs_dir_block *dblock;
333 struct afs_dir_page *dbuf; 334 struct afs_dir_page *dbuf;
334 struct page *page; 335 struct page *page;
335 unsigned blkoff, limit; 336 unsigned blkoff, limit;
336 int ret; 337 int ret;
337 338
338 _enter("{%lu},%u,,", dir->i_ino, *fpos 339 _enter("{%lu},%u,,", dir->i_ino, *fpos);
339 340
340 if (test_bit(AFS_VNODE_DELETED, &AFS_F 341 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dir)->flags)) {
341 _leave(" = -ESTALE"); 342 _leave(" = -ESTALE");
342 return -ESTALE; 343 return -ESTALE;
343 } 344 }
344 345
345 /* round the file position up to the n 346 /* round the file position up to the next entry boundary */
346 *fpos += sizeof(union afs_dirent) - 1; 347 *fpos += sizeof(union afs_dirent) - 1;
347 *fpos &= ~(sizeof(union afs_dirent) - 348 *fpos &= ~(sizeof(union afs_dirent) - 1);
348 349
349 /* walk through the blocks in sequence 350 /* walk through the blocks in sequence */
350 ret = 0; 351 ret = 0;
351 while (*fpos < dir->i_size) { 352 while (*fpos < dir->i_size) {
352 blkoff = *fpos & ~(sizeof(unio 353 blkoff = *fpos & ~(sizeof(union afs_dir_block) - 1);
353 354
354 /* fetch the appropriate page 355 /* fetch the appropriate page from the directory */
355 page = afs_dir_get_page(dir, b 356 page = afs_dir_get_page(dir, blkoff / PAGE_SIZE, key);
356 if (IS_ERR(page)) { 357 if (IS_ERR(page)) {
357 ret = PTR_ERR(page); 358 ret = PTR_ERR(page);
358 break; 359 break;
359 } 360 }
360 361
361 limit = blkoff & ~(PAGE_SIZE - 362 limit = blkoff & ~(PAGE_SIZE - 1);
362 363
363 dbuf = page_address(page); 364 dbuf = page_address(page);
364 365
365 /* deal with the individual bl 366 /* deal with the individual blocks stashed on this page */
366 do { 367 do {
367 dblock = &dbuf->blocks 368 dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) /
368 369 sizeof(union afs_dir_block)];
369 ret = afs_dir_iterate_ 370 ret = afs_dir_iterate_block(fpos, dblock, blkoff,
370 371 cookie, filldir);
371 if (ret != 1) { 372 if (ret != 1) {
372 afs_dir_put_pa 373 afs_dir_put_page(page);
373 goto out; 374 goto out;
374 } 375 }
375 376
376 blkoff += sizeof(union 377 blkoff += sizeof(union afs_dir_block);
377 378
378 } while (*fpos < dir->i_size & 379 } while (*fpos < dir->i_size && blkoff < limit);
379 380
380 afs_dir_put_page(page); 381 afs_dir_put_page(page);
381 ret = 0; 382 ret = 0;
382 } 383 }
383 384
384 out: 385 out:
385 _leave(" = %d", ret); 386 _leave(" = %d", ret);
386 return ret; 387 return ret;
387 } 388 }
388 389
389 /* 390 /*
390 * read an AFS directory 391 * read an AFS directory
391 */ 392 */
392 static int afs_readdir(struct file *file, void 393 static int afs_readdir(struct file *file, void *cookie, filldir_t filldir)
393 { 394 {
394 unsigned fpos; 395 unsigned fpos;
395 int ret; 396 int ret;
396 397
397 _enter("{%Ld,{%lu}}", 398 _enter("{%Ld,{%lu}}",
398 file->f_pos, file->f_path.dentr 399 file->f_pos, file->f_path.dentry->d_inode->i_ino);
399 400
400 ASSERT(file->private_data != NULL); 401 ASSERT(file->private_data != NULL);
401 402
402 fpos = file->f_pos; 403 fpos = file->f_pos;
403 ret = afs_dir_iterate(file->f_path.den 404 ret = afs_dir_iterate(file->f_path.dentry->d_inode, &fpos,
404 cookie, filldir, 405 cookie, filldir, file->private_data);
405 file->f_pos = fpos; 406 file->f_pos = fpos;
406 407
407 _leave(" = %d", ret); 408 _leave(" = %d", ret);
408 return ret; 409 return ret;
409 } 410 }
410 411
411 /* 412 /*
412 * search the directory for a name 413 * search the directory for a name
413 * - if afs_dir_iterate_block() spots this fun 414 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
414 * uniquifier through dtype 415 * uniquifier through dtype
415 */ 416 */
416 static int afs_lookup_filldir(void *_cookie, c 417 static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
417 loff_t fpos, u64 418 loff_t fpos, u64 ino, unsigned dtype)
418 { 419 {
419 struct afs_lookup_cookie *cookie = _co 420 struct afs_lookup_cookie *cookie = _cookie;
420 421
421 _enter("{%s,%Zu},%s,%u,,%llu,%u", 422 _enter("{%s,%Zu},%s,%u,,%llu,%u",
422 cookie->name, cookie->nlen, nam 423 cookie->name, cookie->nlen, name, nlen,
423 (unsigned long long) ino, dtype 424 (unsigned long long) ino, dtype);
424 425
425 /* insanity checks first */ 426 /* insanity checks first */
426 BUILD_BUG_ON(sizeof(union afs_dir_bloc 427 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
427 BUILD_BUG_ON(sizeof(union afs_dirent) 428 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
428 429
429 if (cookie->nlen != nlen || memcmp(coo 430 if (cookie->nlen != nlen || memcmp(cookie->name, name, nlen) != 0) {
430 _leave(" = 0 [no]"); 431 _leave(" = 0 [no]");
431 return 0; 432 return 0;
432 } 433 }
433 434
434 cookie->fid.vnode = ino; 435 cookie->fid.vnode = ino;
435 cookie->fid.unique = dtype; 436 cookie->fid.unique = dtype;
436 cookie->found = 1; 437 cookie->found = 1;
437 438
438 _leave(" = -1 [found]"); 439 _leave(" = -1 [found]");
439 return -1; 440 return -1;
440 } 441 }
441 442
442 /* 443 /*
443 * do a lookup in a directory 444 * do a lookup in a directory
444 * - just returns the FID the dentry name maps 445 * - just returns the FID the dentry name maps to if found
445 */ 446 */
446 static int afs_do_lookup(struct inode *dir, st 447 static int afs_do_lookup(struct inode *dir, struct dentry *dentry,
447 struct afs_fid *fid, 448 struct afs_fid *fid, struct key *key)
448 { 449 {
449 struct afs_lookup_cookie cookie; 450 struct afs_lookup_cookie cookie;
450 struct afs_super_info *as; 451 struct afs_super_info *as;
451 unsigned fpos; 452 unsigned fpos;
452 int ret; 453 int ret;
453 454
454 _enter("{%lu},%p{%s},", dir->i_ino, de 455 _enter("{%lu},%p{%s},", dir->i_ino, dentry, dentry->d_name.name);
455 456
456 as = dir->i_sb->s_fs_info; 457 as = dir->i_sb->s_fs_info;
457 458
458 /* search the directory */ 459 /* search the directory */
459 cookie.name = dentry->d_name.name; 460 cookie.name = dentry->d_name.name;
460 cookie.nlen = dentry->d_name.len; 461 cookie.nlen = dentry->d_name.len;
461 cookie.fid.vid = as->volume->vid; 462 cookie.fid.vid = as->volume->vid;
462 cookie.found = 0; 463 cookie.found = 0;
463 464
464 fpos = 0; 465 fpos = 0;
465 ret = afs_dir_iterate(dir, &fpos, &coo 466 ret = afs_dir_iterate(dir, &fpos, &cookie, afs_lookup_filldir,
466 key); 467 key);
467 if (ret < 0) { 468 if (ret < 0) {
468 _leave(" = %d [iter]", ret); 469 _leave(" = %d [iter]", ret);
469 return ret; 470 return ret;
470 } 471 }
471 472
472 ret = -ENOENT; 473 ret = -ENOENT;
473 if (!cookie.found) { 474 if (!cookie.found) {
474 _leave(" = -ENOENT [not found] 475 _leave(" = -ENOENT [not found]");
475 return -ENOENT; 476 return -ENOENT;
476 } 477 }
477 478
478 *fid = cookie.fid; 479 *fid = cookie.fid;
479 _leave(" = 0 { vn=%u u=%u }", fid->vno 480 _leave(" = 0 { vn=%u u=%u }", fid->vnode, fid->unique);
480 return 0; 481 return 0;
481 } 482 }
482 483
483 /* 484 /*
484 * look up an entry in a directory 485 * look up an entry in a directory
485 */ 486 */
486 static struct dentry *afs_lookup(struct inode 487 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
487 struct nameid 488 struct nameidata *nd)
488 { 489 {
489 struct afs_vnode *vnode; 490 struct afs_vnode *vnode;
490 struct afs_fid fid; 491 struct afs_fid fid;
491 struct inode *inode; 492 struct inode *inode;
492 struct key *key; 493 struct key *key;
493 int ret; 494 int ret;
494 495
495 vnode = AFS_FS_I(dir); 496 vnode = AFS_FS_I(dir);
496 497
497 _enter("{%x:%u},%p{%s},", 498 _enter("{%x:%u},%p{%s},",
498 vnode->fid.vid, vnode->fid.vnod 499 vnode->fid.vid, vnode->fid.vnode, dentry, dentry->d_name.name);
499 500
500 ASSERTCMP(dentry->d_inode, ==, NULL); 501 ASSERTCMP(dentry->d_inode, ==, NULL);
501 502
502 if (dentry->d_name.len >= AFSNAMEMAX) 503 if (dentry->d_name.len >= AFSNAMEMAX) {
503 _leave(" = -ENAMETOOLONG"); 504 _leave(" = -ENAMETOOLONG");
504 return ERR_PTR(-ENAMETOOLONG); 505 return ERR_PTR(-ENAMETOOLONG);
505 } 506 }
506 507
507 if (test_bit(AFS_VNODE_DELETED, &vnode 508 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
508 _leave(" = -ESTALE"); 509 _leave(" = -ESTALE");
509 return ERR_PTR(-ESTALE); 510 return ERR_PTR(-ESTALE);
510 } 511 }
511 512
512 key = afs_request_key(vnode->volume->c 513 key = afs_request_key(vnode->volume->cell);
513 if (IS_ERR(key)) { 514 if (IS_ERR(key)) {
514 _leave(" = %ld [key]", PTR_ERR 515 _leave(" = %ld [key]", PTR_ERR(key));
515 return ERR_CAST(key); 516 return ERR_CAST(key);
516 } 517 }
517 518
518 ret = afs_validate(vnode, key); 519 ret = afs_validate(vnode, key);
519 if (ret < 0) { 520 if (ret < 0) {
520 key_put(key); 521 key_put(key);
521 _leave(" = %d [val]", ret); 522 _leave(" = %d [val]", ret);
522 return ERR_PTR(ret); 523 return ERR_PTR(ret);
523 } 524 }
524 525
525 ret = afs_do_lookup(dir, dentry, &fid, 526 ret = afs_do_lookup(dir, dentry, &fid, key);
526 if (ret < 0) { 527 if (ret < 0) {
527 key_put(key); 528 key_put(key);
528 if (ret == -ENOENT) { 529 if (ret == -ENOENT) {
529 d_add(dentry, NULL); 530 d_add(dentry, NULL);
530 _leave(" = NULL [negat 531 _leave(" = NULL [negative]");
531 return NULL; 532 return NULL;
532 } 533 }
533 _leave(" = %d [do]", ret); 534 _leave(" = %d [do]", ret);
534 return ERR_PTR(ret); 535 return ERR_PTR(ret);
535 } 536 }
536 dentry->d_fsdata = (void *)(unsigned l 537 dentry->d_fsdata = (void *)(unsigned long) vnode->status.data_version;
537 538
538 /* instantiate the dentry */ 539 /* instantiate the dentry */
539 inode = afs_iget(dir->i_sb, key, &fid, 540 inode = afs_iget(dir->i_sb, key, &fid, NULL, NULL);
540 key_put(key); 541 key_put(key);
541 if (IS_ERR(inode)) { 542 if (IS_ERR(inode)) {
542 _leave(" = %ld", PTR_ERR(inode 543 _leave(" = %ld", PTR_ERR(inode));
543 return ERR_CAST(inode); 544 return ERR_CAST(inode);
544 } 545 }
545 546
546 dentry->d_op = &afs_fs_dentry_operatio 547 dentry->d_op = &afs_fs_dentry_operations;
547 548
548 d_add(dentry, inode); 549 d_add(dentry, inode);
549 _leave(" = 0 { vn=%u u=%u } -> { ino=% 550 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%llu }",
550 fid.vnode, 551 fid.vnode,
551 fid.unique, 552 fid.unique,
552 dentry->d_inode->i_ino, 553 dentry->d_inode->i_ino,
553 (unsigned long long)dentry->d_i 554 (unsigned long long)dentry->d_inode->i_version);
554 555
555 return NULL; 556 return NULL;
556 } 557 }
557 558
558 /* 559 /*
559 * check that a dentry lookup hit has found a 560 * check that a dentry lookup hit has found a valid entry
560 * - NOTE! the hit can be a negative hit too, 561 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
561 * inode 562 * inode
562 */ 563 */
563 static int afs_d_revalidate(struct dentry *den 564 static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
564 { 565 {
565 struct afs_vnode *vnode, *dir; 566 struct afs_vnode *vnode, *dir;
566 struct afs_fid fid; !! 567 struct afs_fid uninitialized_var(fid);
567 struct dentry *parent; 568 struct dentry *parent;
568 struct key *key; 569 struct key *key;
569 void *dir_version; 570 void *dir_version;
570 int ret; 571 int ret;
571 572
572 vnode = AFS_FS_I(dentry->d_inode); 573 vnode = AFS_FS_I(dentry->d_inode);
573 574
574 if (dentry->d_inode) 575 if (dentry->d_inode)
575 _enter("{v={%x:%u} n=%s fl=%lx 576 _enter("{v={%x:%u} n=%s fl=%lx},",
576 vnode->fid.vid, vnode-> 577 vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name,
577 vnode->flags); 578 vnode->flags);
578 else 579 else
579 _enter("{neg n=%s}", dentry->d 580 _enter("{neg n=%s}", dentry->d_name.name);
580 581
581 key = afs_request_key(AFS_FS_S(dentry- 582 key = afs_request_key(AFS_FS_S(dentry->d_sb)->volume->cell);
582 if (IS_ERR(key)) 583 if (IS_ERR(key))
583 key = NULL; 584 key = NULL;
584 585
585 /* lock down the parent dentry so we c 586 /* lock down the parent dentry so we can peer at it */
586 parent = dget_parent(dentry); 587 parent = dget_parent(dentry);
587 if (!parent->d_inode) 588 if (!parent->d_inode)
588 goto out_bad; 589 goto out_bad;
589 590
590 dir = AFS_FS_I(parent->d_inode); 591 dir = AFS_FS_I(parent->d_inode);
591 592
592 /* validate the parent directory */ 593 /* validate the parent directory */
593 if (test_bit(AFS_VNODE_MODIFIED, &dir- 594 if (test_bit(AFS_VNODE_MODIFIED, &dir->flags))
594 afs_validate(dir, key); 595 afs_validate(dir, key);
595 596
596 if (test_bit(AFS_VNODE_DELETED, &dir-> 597 if (test_bit(AFS_VNODE_DELETED, &dir->flags)) {
597 _debug("%s: parent dir deleted 598 _debug("%s: parent dir deleted", dentry->d_name.name);
598 goto out_bad; 599 goto out_bad;
599 } 600 }
600 601
601 dir_version = (void *) (unsigned long) 602 dir_version = (void *) (unsigned long) dir->status.data_version;
602 if (dentry->d_fsdata == dir_version) 603 if (dentry->d_fsdata == dir_version)
603 goto out_valid; /* the dir con 604 goto out_valid; /* the dir contents are unchanged */
604 605
605 _debug("dir modified"); 606 _debug("dir modified");
606 607
607 /* search the directory for this vnode 608 /* search the directory for this vnode */
608 ret = afs_do_lookup(&dir->vfs_inode, d 609 ret = afs_do_lookup(&dir->vfs_inode, dentry, &fid, key);
609 switch (ret) { 610 switch (ret) {
610 case 0: 611 case 0:
611 /* the filename maps to someth 612 /* the filename maps to something */
612 if (!dentry->d_inode) 613 if (!dentry->d_inode)
613 goto out_bad; 614 goto out_bad;
614 if (is_bad_inode(dentry->d_ino 615 if (is_bad_inode(dentry->d_inode)) {
615 printk("kAFS: afs_d_re 616 printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
616 parent->d_name. 617 parent->d_name.name, dentry->d_name.name);
617 goto out_bad; 618 goto out_bad;
618 } 619 }
619 620
620 /* if the vnode ID has changed 621 /* if the vnode ID has changed, then the dirent points to a
621 * different file */ 622 * different file */
622 if (fid.vnode != vnode->fid.vn 623 if (fid.vnode != vnode->fid.vnode) {
623 _debug("%s: dirent cha 624 _debug("%s: dirent changed [%u != %u]",
624 dentry->d_name. 625 dentry->d_name.name, fid.vnode,
625 vnode->fid.vnod 626 vnode->fid.vnode);
626 goto not_found; 627 goto not_found;
627 } 628 }
628 629
629 /* if the vnode ID uniqifier h 630 /* if the vnode ID uniqifier has changed, then the file has
630 * been deleted and replaced, 631 * been deleted and replaced, and the original vnode ID has
631 * been reused */ 632 * been reused */
632 if (fid.unique != vnode->fid.u 633 if (fid.unique != vnode->fid.unique) {
633 _debug("%s: file delet 634 _debug("%s: file deleted (uq %u -> %u I:%llu)",
634 dentry->d_name. 635 dentry->d_name.name, fid.unique,
635 vnode->fid.uniq 636 vnode->fid.unique,
636 (unsigned long 637 (unsigned long long)dentry->d_inode->i_version);
637 spin_lock(&vnode->lock 638 spin_lock(&vnode->lock);
638 set_bit(AFS_VNODE_DELE 639 set_bit(AFS_VNODE_DELETED, &vnode->flags);
639 spin_unlock(&vnode->lo 640 spin_unlock(&vnode->lock);
640 goto not_found; 641 goto not_found;
641 } 642 }
642 goto out_valid; 643 goto out_valid;
643 644
644 case -ENOENT: 645 case -ENOENT:
645 /* the filename is unknown */ 646 /* the filename is unknown */
646 _debug("%s: dirent not found", 647 _debug("%s: dirent not found", dentry->d_name.name);
647 if (dentry->d_inode) 648 if (dentry->d_inode)
648 goto not_found; 649 goto not_found;
649 goto out_valid; 650 goto out_valid;
650 651
651 default: 652 default:
652 _debug("failed to iterate dir 653 _debug("failed to iterate dir %s: %d",
653 parent->d_name.name, re 654 parent->d_name.name, ret);
654 goto out_bad; 655 goto out_bad;
655 } 656 }
656 657
657 out_valid: 658 out_valid:
658 dentry->d_fsdata = dir_version; 659 dentry->d_fsdata = dir_version;
659 out_skip: 660 out_skip:
660 dput(parent); 661 dput(parent);
661 key_put(key); 662 key_put(key);
662 _leave(" = 1 [valid]"); 663 _leave(" = 1 [valid]");
663 return 1; 664 return 1;
664 665
665 /* the dirent, if it exists, now point 666 /* the dirent, if it exists, now points to a different vnode */
666 not_found: 667 not_found:
667 spin_lock(&dentry->d_lock); 668 spin_lock(&dentry->d_lock);
668 dentry->d_flags |= DCACHE_NFSFS_RENAME 669 dentry->d_flags |= DCACHE_NFSFS_RENAMED;
669 spin_unlock(&dentry->d_lock); 670 spin_unlock(&dentry->d_lock);
670 671
671 out_bad: 672 out_bad:
672 if (dentry->d_inode) { 673 if (dentry->d_inode) {
673 /* don't unhash if we have sub 674 /* don't unhash if we have submounts */
674 if (have_submounts(dentry)) 675 if (have_submounts(dentry))
675 goto out_skip; 676 goto out_skip;
676 } 677 }
677 678
678 _debug("dropping dentry %s/%s", 679 _debug("dropping dentry %s/%s",
679 parent->d_name.name, dentry->d_ 680 parent->d_name.name, dentry->d_name.name);
680 shrink_dcache_parent(dentry); 681 shrink_dcache_parent(dentry);
681 d_drop(dentry); 682 d_drop(dentry);
682 dput(parent); 683 dput(parent);
683 key_put(key); 684 key_put(key);
684 685
685 _leave(" = 0 [bad]"); 686 _leave(" = 0 [bad]");
686 return 0; 687 return 0;
687 } 688 }
688 689
689 /* 690 /*
690 * allow the VFS to enquire as to whether a de 691 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
691 * sleep) 692 * sleep)
692 * - called from dput() when d_count is going 693 * - called from dput() when d_count is going to 0.
693 * - return 1 to request dentry be unhashed, 0 694 * - return 1 to request dentry be unhashed, 0 otherwise
694 */ 695 */
695 static int afs_d_delete(struct dentry *dentry) 696 static int afs_d_delete(struct dentry *dentry)
696 { 697 {
697 _enter("%s", dentry->d_name.name); 698 _enter("%s", dentry->d_name.name);
698 699
699 if (dentry->d_flags & DCACHE_NFSFS_REN 700 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
700 goto zap; 701 goto zap;
701 702
702 if (dentry->d_inode && 703 if (dentry->d_inode &&
703 test_bit(AFS_VNODE_DELETED, &AFS_F 704 test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags))
704 goto zap; 705 goto zap;
705 706
706 _leave(" = 0 [keep]"); 707 _leave(" = 0 [keep]");
707 return 0; 708 return 0;
708 709
709 zap: 710 zap:
710 _leave(" = 1 [zap]"); 711 _leave(" = 1 [zap]");
711 return 1; 712 return 1;
712 } 713 }
713 714
714 /* 715 /*
715 * handle dentry release 716 * handle dentry release
716 */ 717 */
717 static void afs_d_release(struct dentry *dentr 718 static void afs_d_release(struct dentry *dentry)
718 { 719 {
719 _enter("%s", dentry->d_name.name); 720 _enter("%s", dentry->d_name.name);
720 } 721 }
721 722
722 /* 723 /*
723 * create a directory on an AFS filesystem 724 * create a directory on an AFS filesystem
724 */ 725 */
725 static int afs_mkdir(struct inode *dir, struct 726 static int afs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
726 { 727 {
727 struct afs_file_status status; 728 struct afs_file_status status;
728 struct afs_callback cb; 729 struct afs_callback cb;
729 struct afs_server *server; 730 struct afs_server *server;
730 struct afs_vnode *dvnode, *vnode; 731 struct afs_vnode *dvnode, *vnode;
731 struct afs_fid fid; 732 struct afs_fid fid;
732 struct inode *inode; 733 struct inode *inode;
733 struct key *key; 734 struct key *key;
734 int ret; 735 int ret;
735 736
736 dvnode = AFS_FS_I(dir); 737 dvnode = AFS_FS_I(dir);
737 738
738 _enter("{%x:%u},{%s},%o", 739 _enter("{%x:%u},{%s},%o",
739 dvnode->fid.vid, dvnode->fid.vn 740 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
740 741
741 ret = -ENAMETOOLONG; 742 ret = -ENAMETOOLONG;
742 if (dentry->d_name.len >= AFSNAMEMAX) 743 if (dentry->d_name.len >= AFSNAMEMAX)
743 goto error; 744 goto error;
744 745
745 key = afs_request_key(dvnode->volume-> 746 key = afs_request_key(dvnode->volume->cell);
746 if (IS_ERR(key)) { 747 if (IS_ERR(key)) {
747 ret = PTR_ERR(key); 748 ret = PTR_ERR(key);
748 goto error; 749 goto error;
749 } 750 }
750 751
751 mode |= S_IFDIR; 752 mode |= S_IFDIR;
752 ret = afs_vnode_create(dvnode, key, de 753 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
753 mode, &fid, &st 754 mode, &fid, &status, &cb, &server);
754 if (ret < 0) 755 if (ret < 0)
755 goto mkdir_error; 756 goto mkdir_error;
756 757
757 inode = afs_iget(dir->i_sb, key, &fid, 758 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
758 if (IS_ERR(inode)) { 759 if (IS_ERR(inode)) {
759 /* ENOMEM at a really inconven 760 /* ENOMEM at a really inconvenient time - just abandon the new
760 * directory on the server */ 761 * directory on the server */
761 ret = PTR_ERR(inode); 762 ret = PTR_ERR(inode);
762 goto iget_error; 763 goto iget_error;
763 } 764 }
764 765
765 /* apply the status report we've got f 766 /* apply the status report we've got for the new vnode */
766 vnode = AFS_FS_I(inode); 767 vnode = AFS_FS_I(inode);
767 spin_lock(&vnode->lock); 768 spin_lock(&vnode->lock);
768 vnode->update_cnt++; 769 vnode->update_cnt++;
769 spin_unlock(&vnode->lock); 770 spin_unlock(&vnode->lock);
770 afs_vnode_finalise_status_update(vnode 771 afs_vnode_finalise_status_update(vnode, server);
771 afs_put_server(server); 772 afs_put_server(server);
772 773
773 d_instantiate(dentry, inode); 774 d_instantiate(dentry, inode);
774 if (d_unhashed(dentry)) { 775 if (d_unhashed(dentry)) {
775 _debug("not hashed"); 776 _debug("not hashed");
776 d_rehash(dentry); 777 d_rehash(dentry);
777 } 778 }
778 key_put(key); 779 key_put(key);
779 _leave(" = 0"); 780 _leave(" = 0");
780 return 0; 781 return 0;
781 782
782 iget_error: 783 iget_error:
783 afs_put_server(server); 784 afs_put_server(server);
784 mkdir_error: 785 mkdir_error:
785 key_put(key); 786 key_put(key);
786 error: 787 error:
787 d_drop(dentry); 788 d_drop(dentry);
788 _leave(" = %d", ret); 789 _leave(" = %d", ret);
789 return ret; 790 return ret;
790 } 791 }
791 792
792 /* 793 /*
793 * remove a directory from an AFS filesystem 794 * remove a directory from an AFS filesystem
794 */ 795 */
795 static int afs_rmdir(struct inode *dir, struct 796 static int afs_rmdir(struct inode *dir, struct dentry *dentry)
796 { 797 {
797 struct afs_vnode *dvnode, *vnode; 798 struct afs_vnode *dvnode, *vnode;
798 struct key *key; 799 struct key *key;
799 int ret; 800 int ret;
800 801
801 dvnode = AFS_FS_I(dir); 802 dvnode = AFS_FS_I(dir);
802 803
803 _enter("{%x:%u},{%s}", 804 _enter("{%x:%u},{%s}",
804 dvnode->fid.vid, dvnode->fid.vn 805 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
805 806
806 ret = -ENAMETOOLONG; 807 ret = -ENAMETOOLONG;
807 if (dentry->d_name.len >= AFSNAMEMAX) 808 if (dentry->d_name.len >= AFSNAMEMAX)
808 goto error; 809 goto error;
809 810
810 key = afs_request_key(dvnode->volume-> 811 key = afs_request_key(dvnode->volume->cell);
811 if (IS_ERR(key)) { 812 if (IS_ERR(key)) {
812 ret = PTR_ERR(key); 813 ret = PTR_ERR(key);
813 goto error; 814 goto error;
814 } 815 }
815 816
816 ret = afs_vnode_remove(dvnode, key, de 817 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, true);
817 if (ret < 0) 818 if (ret < 0)
818 goto rmdir_error; 819 goto rmdir_error;
819 820
820 if (dentry->d_inode) { 821 if (dentry->d_inode) {
821 vnode = AFS_FS_I(dentry->d_ino 822 vnode = AFS_FS_I(dentry->d_inode);
822 clear_nlink(&vnode->vfs_inode) 823 clear_nlink(&vnode->vfs_inode);
823 set_bit(AFS_VNODE_DELETED, &vn 824 set_bit(AFS_VNODE_DELETED, &vnode->flags);
824 afs_discard_callback_on_delete 825 afs_discard_callback_on_delete(vnode);
825 } 826 }
826 827
827 key_put(key); 828 key_put(key);
828 _leave(" = 0"); 829 _leave(" = 0");
829 return 0; 830 return 0;
830 831
831 rmdir_error: 832 rmdir_error:
832 key_put(key); 833 key_put(key);
833 error: 834 error:
834 _leave(" = %d", ret); 835 _leave(" = %d", ret);
835 return ret; 836 return ret;
836 } 837 }
837 838
838 /* 839 /*
839 * remove a file from an AFS filesystem 840 * remove a file from an AFS filesystem
840 */ 841 */
841 static int afs_unlink(struct inode *dir, struc 842 static int afs_unlink(struct inode *dir, struct dentry *dentry)
842 { 843 {
843 struct afs_vnode *dvnode, *vnode; 844 struct afs_vnode *dvnode, *vnode;
844 struct key *key; 845 struct key *key;
845 int ret; 846 int ret;
846 847
847 dvnode = AFS_FS_I(dir); 848 dvnode = AFS_FS_I(dir);
848 849
849 _enter("{%x:%u},{%s}", 850 _enter("{%x:%u},{%s}",
850 dvnode->fid.vid, dvnode->fid.vn 851 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
851 852
852 ret = -ENAMETOOLONG; 853 ret = -ENAMETOOLONG;
853 if (dentry->d_name.len >= AFSNAMEMAX) 854 if (dentry->d_name.len >= AFSNAMEMAX)
854 goto error; 855 goto error;
855 856
856 key = afs_request_key(dvnode->volume-> 857 key = afs_request_key(dvnode->volume->cell);
857 if (IS_ERR(key)) { 858 if (IS_ERR(key)) {
858 ret = PTR_ERR(key); 859 ret = PTR_ERR(key);
859 goto error; 860 goto error;
860 } 861 }
861 862
862 if (dentry->d_inode) { 863 if (dentry->d_inode) {
863 vnode = AFS_FS_I(dentry->d_ino 864 vnode = AFS_FS_I(dentry->d_inode);
864 865
865 /* make sure we have a callbac 866 /* make sure we have a callback promise on the victim */
866 ret = afs_validate(vnode, key) 867 ret = afs_validate(vnode, key);
867 if (ret < 0) 868 if (ret < 0)
868 goto error; 869 goto error;
869 } 870 }
870 871
871 ret = afs_vnode_remove(dvnode, key, de 872 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, false);
872 if (ret < 0) 873 if (ret < 0)
873 goto remove_error; 874 goto remove_error;
874 875
875 if (dentry->d_inode) { 876 if (dentry->d_inode) {
876 /* if the file wasn't deleted 877 /* if the file wasn't deleted due to excess hard links, the
877 * fileserver will break the c 878 * fileserver will break the callback promise on the file - if
878 * it had one - before it retu 879 * it had one - before it returns to us, and if it was deleted,
879 * it won't 880 * it won't
880 * 881 *
881 * however, if we didn't have 882 * however, if we didn't have a callback promise outstanding,
882 * or it was outstanding on a 883 * or it was outstanding on a different server, then it won't
883 * break it either... 884 * break it either...
884 */ 885 */
885 vnode = AFS_FS_I(dentry->d_ino 886 vnode = AFS_FS_I(dentry->d_inode);
886 if (test_bit(AFS_VNODE_DELETED 887 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
887 _debug("AFS_VNODE_DELE 888 _debug("AFS_VNODE_DELETED");
888 if (test_bit(AFS_VNODE_CB_BROK 889 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
889 _debug("AFS_VNODE_CB_B 890 _debug("AFS_VNODE_CB_BROKEN");
890 set_bit(AFS_VNODE_CB_BROKEN, & 891 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
891 ret = afs_validate(vnode, key) 892 ret = afs_validate(vnode, key);
892 _debug("nlink %d [val %d]", vn 893 _debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
893 } 894 }
894 895
895 key_put(key); 896 key_put(key);
896 _leave(" = 0"); 897 _leave(" = 0");
897 return 0; 898 return 0;
898 899
899 remove_error: 900 remove_error:
900 key_put(key); 901 key_put(key);
901 error: 902 error:
902 _leave(" = %d", ret); 903 _leave(" = %d", ret);
903 return ret; 904 return ret;
904 } 905 }
905 906
906 /* 907 /*
907 * create a regular file on an AFS filesystem 908 * create a regular file on an AFS filesystem
908 */ 909 */
909 static int afs_create(struct inode *dir, struc 910 static int afs_create(struct inode *dir, struct dentry *dentry, int mode,
910 struct nameidata *nd) 911 struct nameidata *nd)
911 { 912 {
912 struct afs_file_status status; 913 struct afs_file_status status;
913 struct afs_callback cb; 914 struct afs_callback cb;
914 struct afs_server *server; 915 struct afs_server *server;
915 struct afs_vnode *dvnode, *vnode; 916 struct afs_vnode *dvnode, *vnode;
916 struct afs_fid fid; 917 struct afs_fid fid;
917 struct inode *inode; 918 struct inode *inode;
918 struct key *key; 919 struct key *key;
919 int ret; 920 int ret;
920 921
921 dvnode = AFS_FS_I(dir); 922 dvnode = AFS_FS_I(dir);
922 923
923 _enter("{%x:%u},{%s},%o,", 924 _enter("{%x:%u},{%s},%o,",
924 dvnode->fid.vid, dvnode->fid.vn 925 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
925 926
926 ret = -ENAMETOOLONG; 927 ret = -ENAMETOOLONG;
927 if (dentry->d_name.len >= AFSNAMEMAX) 928 if (dentry->d_name.len >= AFSNAMEMAX)
928 goto error; 929 goto error;
929 930
930 key = afs_request_key(dvnode->volume-> 931 key = afs_request_key(dvnode->volume->cell);
931 if (IS_ERR(key)) { 932 if (IS_ERR(key)) {
932 ret = PTR_ERR(key); 933 ret = PTR_ERR(key);
933 goto error; 934 goto error;
934 } 935 }
935 936
936 mode |= S_IFREG; 937 mode |= S_IFREG;
937 ret = afs_vnode_create(dvnode, key, de 938 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
938 mode, &fid, &st 939 mode, &fid, &status, &cb, &server);
939 if (ret < 0) 940 if (ret < 0)
940 goto create_error; 941 goto create_error;
941 942
942 inode = afs_iget(dir->i_sb, key, &fid, 943 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
943 if (IS_ERR(inode)) { 944 if (IS_ERR(inode)) {
944 /* ENOMEM at a really inconven 945 /* ENOMEM at a really inconvenient time - just abandon the new
945 * directory on the server */ 946 * directory on the server */
946 ret = PTR_ERR(inode); 947 ret = PTR_ERR(inode);
947 goto iget_error; 948 goto iget_error;
948 } 949 }
949 950
950 /* apply the status report we've got f 951 /* apply the status report we've got for the new vnode */
951 vnode = AFS_FS_I(inode); 952 vnode = AFS_FS_I(inode);
952 spin_lock(&vnode->lock); 953 spin_lock(&vnode->lock);
953 vnode->update_cnt++; 954 vnode->update_cnt++;
954 spin_unlock(&vnode->lock); 955 spin_unlock(&vnode->lock);
955 afs_vnode_finalise_status_update(vnode 956 afs_vnode_finalise_status_update(vnode, server);
956 afs_put_server(server); 957 afs_put_server(server);
957 958
958 d_instantiate(dentry, inode); 959 d_instantiate(dentry, inode);
959 if (d_unhashed(dentry)) { 960 if (d_unhashed(dentry)) {
960 _debug("not hashed"); 961 _debug("not hashed");
961 d_rehash(dentry); 962 d_rehash(dentry);
962 } 963 }
963 key_put(key); 964 key_put(key);
964 _leave(" = 0"); 965 _leave(" = 0");
965 return 0; 966 return 0;
966 967
967 iget_error: 968 iget_error:
968 afs_put_server(server); 969 afs_put_server(server);
969 create_error: 970 create_error:
970 key_put(key); 971 key_put(key);
971 error: 972 error:
972 d_drop(dentry); 973 d_drop(dentry);
973 _leave(" = %d", ret); 974 _leave(" = %d", ret);
974 return ret; 975 return ret;
975 } 976 }
976 977
977 /* 978 /*
978 * create a hard link between files in an AFS 979 * create a hard link between files in an AFS filesystem
979 */ 980 */
980 static int afs_link(struct dentry *from, struc 981 static int afs_link(struct dentry *from, struct inode *dir,
981 struct dentry *dentry) 982 struct dentry *dentry)
982 { 983 {
983 struct afs_vnode *dvnode, *vnode; 984 struct afs_vnode *dvnode, *vnode;
984 struct key *key; 985 struct key *key;
985 int ret; 986 int ret;
986 987
987 vnode = AFS_FS_I(from->d_inode); 988 vnode = AFS_FS_I(from->d_inode);
988 dvnode = AFS_FS_I(dir); 989 dvnode = AFS_FS_I(dir);
989 990
990 _enter("{%x:%u},{%x:%u},{%s}", 991 _enter("{%x:%u},{%x:%u},{%s}",
991 vnode->fid.vid, vnode->fid.vnod 992 vnode->fid.vid, vnode->fid.vnode,
992 dvnode->fid.vid, dvnode->fid.vn 993 dvnode->fid.vid, dvnode->fid.vnode,
993 dentry->d_name.name); 994 dentry->d_name.name);
994 995
995 ret = -ENAMETOOLONG; 996 ret = -ENAMETOOLONG;
996 if (dentry->d_name.len >= AFSNAMEMAX) 997 if (dentry->d_name.len >= AFSNAMEMAX)
997 goto error; 998 goto error;
998 999
999 key = afs_request_key(dvnode->volume-> 1000 key = afs_request_key(dvnode->volume->cell);
1000 if (IS_ERR(key)) { 1001 if (IS_ERR(key)) {
1001 ret = PTR_ERR(key); 1002 ret = PTR_ERR(key);
1002 goto error; 1003 goto error;
1003 } 1004 }
1004 1005
1005 ret = afs_vnode_link(dvnode, vnode, k 1006 ret = afs_vnode_link(dvnode, vnode, key, dentry->d_name.name);
1006 if (ret < 0) 1007 if (ret < 0)
1007 goto link_error; 1008 goto link_error;
1008 1009
1009 atomic_inc(&vnode->vfs_inode.i_count) 1010 atomic_inc(&vnode->vfs_inode.i_count);
1010 d_instantiate(dentry, &vnode->vfs_ino 1011 d_instantiate(dentry, &vnode->vfs_inode);
1011 key_put(key); 1012 key_put(key);
1012 _leave(" = 0"); 1013 _leave(" = 0");
1013 return 0; 1014 return 0;
1014 1015
1015 link_error: 1016 link_error:
1016 key_put(key); 1017 key_put(key);
1017 error: 1018 error:
1018 d_drop(dentry); 1019 d_drop(dentry);
1019 _leave(" = %d", ret); 1020 _leave(" = %d", ret);
1020 return ret; 1021 return ret;
1021 } 1022 }
1022 1023
1023 /* 1024 /*
1024 * create a symlink in an AFS filesystem 1025 * create a symlink in an AFS filesystem
1025 */ 1026 */
1026 static int afs_symlink(struct inode *dir, str 1027 static int afs_symlink(struct inode *dir, struct dentry *dentry,
1027 const char *content) 1028 const char *content)
1028 { 1029 {
1029 struct afs_file_status status; 1030 struct afs_file_status status;
1030 struct afs_server *server; 1031 struct afs_server *server;
1031 struct afs_vnode *dvnode, *vnode; 1032 struct afs_vnode *dvnode, *vnode;
1032 struct afs_fid fid; 1033 struct afs_fid fid;
1033 struct inode *inode; 1034 struct inode *inode;
1034 struct key *key; 1035 struct key *key;
1035 int ret; 1036 int ret;
1036 1037
1037 dvnode = AFS_FS_I(dir); 1038 dvnode = AFS_FS_I(dir);
1038 1039
1039 _enter("{%x:%u},{%s},%s", 1040 _enter("{%x:%u},{%s},%s",
1040 dvnode->fid.vid, dvnode->fid.v 1041 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name,
1041 content); 1042 content);
1042 1043
1043 ret = -ENAMETOOLONG; 1044 ret = -ENAMETOOLONG;
1044 if (dentry->d_name.len >= AFSNAMEMAX) 1045 if (dentry->d_name.len >= AFSNAMEMAX)
1045 goto error; 1046 goto error;
1046 1047
1047 ret = -EINVAL; 1048 ret = -EINVAL;
1048 if (strlen(content) >= AFSPATHMAX) 1049 if (strlen(content) >= AFSPATHMAX)
1049 goto error; 1050 goto error;
1050 1051
1051 key = afs_request_key(dvnode->volume- 1052 key = afs_request_key(dvnode->volume->cell);
1052 if (IS_ERR(key)) { 1053 if (IS_ERR(key)) {
1053 ret = PTR_ERR(key); 1054 ret = PTR_ERR(key);
1054 goto error; 1055 goto error;
1055 } 1056 }
1056 1057
1057 ret = afs_vnode_symlink(dvnode, key, 1058 ret = afs_vnode_symlink(dvnode, key, dentry->d_name.name, content,
1058 &fid, &status 1059 &fid, &status, &server);
1059 if (ret < 0) 1060 if (ret < 0)
1060 goto create_error; 1061 goto create_error;
1061 1062
1062 inode = afs_iget(dir->i_sb, key, &fid 1063 inode = afs_iget(dir->i_sb, key, &fid, &status, NULL);
1063 if (IS_ERR(inode)) { 1064 if (IS_ERR(inode)) {
1064 /* ENOMEM at a really inconve 1065 /* ENOMEM at a really inconvenient time - just abandon the new
1065 * directory on the server */ 1066 * directory on the server */
1066 ret = PTR_ERR(inode); 1067 ret = PTR_ERR(inode);
1067 goto iget_error; 1068 goto iget_error;
1068 } 1069 }
1069 1070
1070 /* apply the status report we've got 1071 /* apply the status report we've got for the new vnode */
1071 vnode = AFS_FS_I(inode); 1072 vnode = AFS_FS_I(inode);
1072 spin_lock(&vnode->lock); 1073 spin_lock(&vnode->lock);
1073 vnode->update_cnt++; 1074 vnode->update_cnt++;
1074 spin_unlock(&vnode->lock); 1075 spin_unlock(&vnode->lock);
1075 afs_vnode_finalise_status_update(vnod 1076 afs_vnode_finalise_status_update(vnode, server);
1076 afs_put_server(server); 1077 afs_put_server(server);
1077 1078
1078 d_instantiate(dentry, inode); 1079 d_instantiate(dentry, inode);
1079 if (d_unhashed(dentry)) { 1080 if (d_unhashed(dentry)) {
1080 _debug("not hashed"); 1081 _debug("not hashed");
1081 d_rehash(dentry); 1082 d_rehash(dentry);
1082 } 1083 }
1083 key_put(key); 1084 key_put(key);
1084 _leave(" = 0"); 1085 _leave(" = 0");
1085 return 0; 1086 return 0;
1086 1087
1087 iget_error: 1088 iget_error:
1088 afs_put_server(server); 1089 afs_put_server(server);
1089 create_error: 1090 create_error:
1090 key_put(key); 1091 key_put(key);
1091 error: 1092 error:
1092 d_drop(dentry); 1093 d_drop(dentry);
1093 _leave(" = %d", ret); 1094 _leave(" = %d", ret);
1094 return ret; 1095 return ret;
1095 } 1096 }
1096 1097
1097 /* 1098 /*
1098 * rename a file in an AFS filesystem and/or 1099 * rename a file in an AFS filesystem and/or move it between directories
1099 */ 1100 */
1100 static int afs_rename(struct inode *old_dir, 1101 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1101 struct inode *new_dir, 1102 struct inode *new_dir, struct dentry *new_dentry)
1102 { 1103 {
1103 struct afs_vnode *orig_dvnode, *new_d 1104 struct afs_vnode *orig_dvnode, *new_dvnode, *vnode;
1104 struct key *key; 1105 struct key *key;
1105 int ret; 1106 int ret;
1106 1107
1107 vnode = AFS_FS_I(old_dentry->d_inode) 1108 vnode = AFS_FS_I(old_dentry->d_inode);
1108 orig_dvnode = AFS_FS_I(old_dir); 1109 orig_dvnode = AFS_FS_I(old_dir);
1109 new_dvnode = AFS_FS_I(new_dir); 1110 new_dvnode = AFS_FS_I(new_dir);
1110 1111
1111 _enter("{%x:%u},{%x:%u},{%x:%u},{%s}" 1112 _enter("{%x:%u},{%x:%u},{%x:%u},{%s}",
1112 orig_dvnode->fid.vid, orig_dvn 1113 orig_dvnode->fid.vid, orig_dvnode->fid.vnode,
1113 vnode->fid.vid, vnode->fid.vno 1114 vnode->fid.vid, vnode->fid.vnode,
1114 new_dvnode->fid.vid, new_dvnod 1115 new_dvnode->fid.vid, new_dvnode->fid.vnode,
1115 new_dentry->d_name.name); 1116 new_dentry->d_name.name);
1116 1117
1117 ret = -ENAMETOOLONG; 1118 ret = -ENAMETOOLONG;
1118 if (new_dentry->d_name.len >= AFSNAME 1119 if (new_dentry->d_name.len >= AFSNAMEMAX)
1119 goto error; 1120 goto error;
1120 1121
1121 key = afs_request_key(orig_dvnode->vo 1122 key = afs_request_key(orig_dvnode->volume->cell);
1122 if (IS_ERR(key)) { 1123 if (IS_ERR(key)) {
1123 ret = PTR_ERR(key); 1124 ret = PTR_ERR(key);
1124 goto error; 1125 goto error;
1125 } 1126 }
1126 1127
1127 ret = afs_vnode_rename(orig_dvnode, n 1128 ret = afs_vnode_rename(orig_dvnode, new_dvnode, key,
1128 old_dentry->d_ 1129 old_dentry->d_name.name,
1129 new_dentry->d_ 1130 new_dentry->d_name.name);
1130 if (ret < 0) 1131 if (ret < 0)
1131 goto rename_error; 1132 goto rename_error;
1132 key_put(key); 1133 key_put(key);
1133 _leave(" = 0"); 1134 _leave(" = 0");
1134 return 0; 1135 return 0;
1135 1136
1136 rename_error: 1137 rename_error:
1137 key_put(key); 1138 key_put(key);
1138 error: 1139 error:
1139 d_drop(new_dentry); 1140 d_drop(new_dentry);
1140 _leave(" = %d", ret); 1141 _leave(" = %d", ret);
1141 return ret; 1142 return ret;
1142 } 1143 }
1143 1144
|
This page was automatically generated by the
LXR engine.
|