diff options
author | David Howells <dhowells@redhat.com> | 2018-04-06 09:17:25 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2018-04-09 16:54:48 -0400 |
commit | 0031763698d197d779fcafe5685f6e7818b70d32 (patch) | |
tree | c394fab3401bb476c034c51dcefb1da1d36e55fa /fs | |
parent | 4ea219a839bf85cf774299e2f817e609ba7ef331 (diff) |
afs: Adjust the directory XDR structures
Adjust the AFS directory XDR structures in a number of superficial ways:
(1) Rename them to all begin afs_xdr_.
(2) Use u8 instead of uint8_t.
(3) Mark the structures as __packed so they don't get rearranged by the
compiler.
(4) Rename the hdr member of afs_xdr_dir_block to meta.
(5) Rename the pagehdr member of afs_xdr_dir_block to hdr.
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/afs/dir.c | 62 | ||||
-rw-r--r-- | fs/afs/xdr_fs.h | 44 |
2 files changed, 53 insertions, 53 deletions
diff --git a/fs/afs/dir.c b/fs/afs/dir.c index a2422fbcbf72..f078ae63d870 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c | |||
@@ -111,7 +111,7 @@ struct afs_lookup_cookie { | |||
111 | static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, | 111 | static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, |
112 | loff_t i_size) | 112 | loff_t i_size) |
113 | { | 113 | { |
114 | struct afs_dir_page *dbuf; | 114 | struct afs_xdr_dir_page *dbuf; |
115 | loff_t latter, off; | 115 | loff_t latter, off; |
116 | int tmp, qty; | 116 | int tmp, qty; |
117 | 117 | ||
@@ -127,15 +127,15 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, | |||
127 | qty = PAGE_SIZE; | 127 | qty = PAGE_SIZE; |
128 | else | 128 | else |
129 | qty = latter; | 129 | qty = latter; |
130 | qty /= sizeof(union afs_dir_block); | 130 | qty /= sizeof(union afs_xdr_dir_block); |
131 | 131 | ||
132 | /* check them */ | 132 | /* check them */ |
133 | dbuf = page_address(page); | 133 | dbuf = page_address(page); |
134 | for (tmp = 0; tmp < qty; tmp++) { | 134 | for (tmp = 0; tmp < qty; tmp++) { |
135 | if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) { | 135 | if (dbuf->blocks[tmp].hdr.magic != AFS_DIR_MAGIC) { |
136 | printk("kAFS: %s(%lx): bad magic %d/%d is %04hx\n", | 136 | printk("kAFS: %s(%lx): bad magic %d/%d is %04hx\n", |
137 | __func__, dvnode->vfs_inode.i_ino, tmp, qty, | 137 | __func__, dvnode->vfs_inode.i_ino, tmp, qty, |
138 | ntohs(dbuf->blocks[tmp].pagehdr.magic)); | 138 | ntohs(dbuf->blocks[tmp].hdr.magic)); |
139 | trace_afs_dir_check_failed(dvnode, off, i_size); | 139 | trace_afs_dir_check_failed(dvnode, off, i_size); |
140 | goto error; | 140 | goto error; |
141 | } | 141 | } |
@@ -156,8 +156,8 @@ static int afs_dir_open(struct inode *inode, struct file *file) | |||
156 | { | 156 | { |
157 | _enter("{%lu}", inode->i_ino); | 157 | _enter("{%lu}", inode->i_ino); |
158 | 158 | ||
159 | BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048); | 159 | BUILD_BUG_ON(sizeof(union afs_xdr_dir_block) != 2048); |
160 | BUILD_BUG_ON(sizeof(union afs_dirent) != 32); | 160 | BUILD_BUG_ON(sizeof(union afs_xdr_dirent) != 32); |
161 | 161 | ||
162 | if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags)) | 162 | if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags)) |
163 | return -ENOENT; | 163 | return -ENOENT; |
@@ -310,17 +310,17 @@ content_has_grown: | |||
310 | * deal with one block in an AFS directory | 310 | * deal with one block in an AFS directory |
311 | */ | 311 | */ |
312 | static int afs_dir_iterate_block(struct dir_context *ctx, | 312 | static int afs_dir_iterate_block(struct dir_context *ctx, |
313 | union afs_dir_block *block, | 313 | union afs_xdr_dir_block *block, |
314 | unsigned blkoff) | 314 | unsigned blkoff) |
315 | { | 315 | { |
316 | union afs_dirent *dire; | 316 | union afs_xdr_dirent *dire; |
317 | unsigned offset, next, curr; | 317 | unsigned offset, next, curr; |
318 | size_t nlen; | 318 | size_t nlen; |
319 | int tmp; | 319 | int tmp; |
320 | 320 | ||
321 | _enter("%u,%x,%p,,",(unsigned)ctx->pos,blkoff,block); | 321 | _enter("%u,%x,%p,,",(unsigned)ctx->pos,blkoff,block); |
322 | 322 | ||
323 | curr = (ctx->pos - blkoff) / sizeof(union afs_dirent); | 323 | curr = (ctx->pos - blkoff) / sizeof(union afs_xdr_dirent); |
324 | 324 | ||
325 | /* walk through the block, an entry at a time */ | 325 | /* walk through the block, an entry at a time */ |
326 | for (offset = (blkoff == 0 ? AFS_DIR_RESV_BLOCKS0 : AFS_DIR_RESV_BLOCKS); | 326 | for (offset = (blkoff == 0 ? AFS_DIR_RESV_BLOCKS0 : AFS_DIR_RESV_BLOCKS); |
@@ -330,13 +330,13 @@ static int afs_dir_iterate_block(struct dir_context *ctx, | |||
330 | next = offset + 1; | 330 | next = offset + 1; |
331 | 331 | ||
332 | /* skip entries marked unused in the bitmap */ | 332 | /* skip entries marked unused in the bitmap */ |
333 | if (!(block->pagehdr.bitmap[offset / 8] & | 333 | if (!(block->hdr.bitmap[offset / 8] & |
334 | (1 << (offset % 8)))) { | 334 | (1 << (offset % 8)))) { |
335 | _debug("ENT[%zu.%u]: unused", | 335 | _debug("ENT[%zu.%u]: unused", |
336 | blkoff / sizeof(union afs_dir_block), offset); | 336 | blkoff / sizeof(union afs_xdr_dir_block), offset); |
337 | if (offset >= curr) | 337 | if (offset >= curr) |
338 | ctx->pos = blkoff + | 338 | ctx->pos = blkoff + |
339 | next * sizeof(union afs_dirent); | 339 | next * sizeof(union afs_xdr_dirent); |
340 | continue; | 340 | continue; |
341 | } | 341 | } |
342 | 342 | ||
@@ -344,34 +344,34 @@ static int afs_dir_iterate_block(struct dir_context *ctx, | |||
344 | dire = &block->dirents[offset]; | 344 | dire = &block->dirents[offset]; |
345 | nlen = strnlen(dire->u.name, | 345 | nlen = strnlen(dire->u.name, |
346 | sizeof(*block) - | 346 | sizeof(*block) - |
347 | offset * sizeof(union afs_dirent)); | 347 | offset * sizeof(union afs_xdr_dirent)); |
348 | 348 | ||
349 | _debug("ENT[%zu.%u]: %s %zu \"%s\"", | 349 | _debug("ENT[%zu.%u]: %s %zu \"%s\"", |
350 | blkoff / sizeof(union afs_dir_block), offset, | 350 | blkoff / sizeof(union afs_xdr_dir_block), offset, |
351 | (offset < curr ? "skip" : "fill"), | 351 | (offset < curr ? "skip" : "fill"), |
352 | nlen, dire->u.name); | 352 | nlen, dire->u.name); |
353 | 353 | ||
354 | /* work out where the next possible entry is */ | 354 | /* work out where the next possible entry is */ |
355 | for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) { | 355 | for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_xdr_dirent)) { |
356 | if (next >= AFS_DIR_SLOTS_PER_BLOCK) { | 356 | if (next >= AFS_DIR_SLOTS_PER_BLOCK) { |
357 | _debug("ENT[%zu.%u]:" | 357 | _debug("ENT[%zu.%u]:" |
358 | " %u travelled beyond end dir block" | 358 | " %u travelled beyond end dir block" |
359 | " (len %u/%zu)", | 359 | " (len %u/%zu)", |
360 | blkoff / sizeof(union afs_dir_block), | 360 | blkoff / sizeof(union afs_xdr_dir_block), |
361 | offset, next, tmp, nlen); | 361 | offset, next, tmp, nlen); |
362 | return -EIO; | 362 | return -EIO; |
363 | } | 363 | } |
364 | if (!(block->pagehdr.bitmap[next / 8] & | 364 | if (!(block->hdr.bitmap[next / 8] & |
365 | (1 << (next % 8)))) { | 365 | (1 << (next % 8)))) { |
366 | _debug("ENT[%zu.%u]:" | 366 | _debug("ENT[%zu.%u]:" |
367 | " %u unmarked extension (len %u/%zu)", | 367 | " %u unmarked extension (len %u/%zu)", |
368 | blkoff / sizeof(union afs_dir_block), | 368 | blkoff / sizeof(union afs_xdr_dir_block), |
369 | offset, next, tmp, nlen); | 369 | offset, next, tmp, nlen); |
370 | return -EIO; | 370 | return -EIO; |
371 | } | 371 | } |
372 | 372 | ||
373 | _debug("ENT[%zu.%u]: ext %u/%zu", | 373 | _debug("ENT[%zu.%u]: ext %u/%zu", |
374 | blkoff / sizeof(union afs_dir_block), | 374 | blkoff / sizeof(union afs_xdr_dir_block), |
375 | next, tmp, nlen); | 375 | next, tmp, nlen); |
376 | next++; | 376 | next++; |
377 | } | 377 | } |
@@ -390,7 +390,7 @@ static int afs_dir_iterate_block(struct dir_context *ctx, | |||
390 | return 0; | 390 | return 0; |
391 | } | 391 | } |
392 | 392 | ||
393 | ctx->pos = blkoff + next * sizeof(union afs_dirent); | 393 | ctx->pos = blkoff + next * sizeof(union afs_xdr_dirent); |
394 | } | 394 | } |
395 | 395 | ||
396 | _leave(" = 1 [more]"); | 396 | _leave(" = 1 [more]"); |
@@ -404,8 +404,8 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx, | |||
404 | struct key *key) | 404 | struct key *key) |
405 | { | 405 | { |
406 | struct afs_vnode *dvnode = AFS_FS_I(dir); | 406 | struct afs_vnode *dvnode = AFS_FS_I(dir); |
407 | union afs_dir_block *dblock; | 407 | struct afs_xdr_dir_page *dbuf; |
408 | struct afs_dir_page *dbuf; | 408 | union afs_xdr_dir_block *dblock; |
409 | struct afs_read *req; | 409 | struct afs_read *req; |
410 | struct page *page; | 410 | struct page *page; |
411 | unsigned blkoff, limit; | 411 | unsigned blkoff, limit; |
@@ -423,13 +423,13 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx, | |||
423 | return PTR_ERR(req); | 423 | return PTR_ERR(req); |
424 | 424 | ||
425 | /* round the file position up to the next entry boundary */ | 425 | /* round the file position up to the next entry boundary */ |
426 | ctx->pos += sizeof(union afs_dirent) - 1; | 426 | ctx->pos += sizeof(union afs_xdr_dirent) - 1; |
427 | ctx->pos &= ~(sizeof(union afs_dirent) - 1); | 427 | ctx->pos &= ~(sizeof(union afs_xdr_dirent) - 1); |
428 | 428 | ||
429 | /* walk through the blocks in sequence */ | 429 | /* walk through the blocks in sequence */ |
430 | ret = 0; | 430 | ret = 0; |
431 | while (ctx->pos < req->actual_len) { | 431 | while (ctx->pos < req->actual_len) { |
432 | blkoff = ctx->pos & ~(sizeof(union afs_dir_block) - 1); | 432 | blkoff = ctx->pos & ~(sizeof(union afs_xdr_dir_block) - 1); |
433 | 433 | ||
434 | /* Fetch the appropriate page from the directory and re-add it | 434 | /* Fetch the appropriate page from the directory and re-add it |
435 | * to the LRU. | 435 | * to the LRU. |
@@ -448,14 +448,14 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx, | |||
448 | /* deal with the individual blocks stashed on this page */ | 448 | /* deal with the individual blocks stashed on this page */ |
449 | do { | 449 | do { |
450 | dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) / | 450 | dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) / |
451 | sizeof(union afs_dir_block)]; | 451 | sizeof(union afs_xdr_dir_block)]; |
452 | ret = afs_dir_iterate_block(ctx, dblock, blkoff); | 452 | ret = afs_dir_iterate_block(ctx, dblock, blkoff); |
453 | if (ret != 1) { | 453 | if (ret != 1) { |
454 | kunmap(page); | 454 | kunmap(page); |
455 | goto out; | 455 | goto out; |
456 | } | 456 | } |
457 | 457 | ||
458 | blkoff += sizeof(union afs_dir_block); | 458 | blkoff += sizeof(union afs_xdr_dir_block); |
459 | 459 | ||
460 | } while (ctx->pos < dir->i_size && blkoff < limit); | 460 | } while (ctx->pos < dir->i_size && blkoff < limit); |
461 | 461 | ||
@@ -493,8 +493,8 @@ static int afs_lookup_one_filldir(struct dir_context *ctx, const char *name, | |||
493 | (unsigned long long) ino, dtype); | 493 | (unsigned long long) ino, dtype); |
494 | 494 | ||
495 | /* insanity checks first */ | 495 | /* insanity checks first */ |
496 | BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048); | 496 | BUILD_BUG_ON(sizeof(union afs_xdr_dir_block) != 2048); |
497 | BUILD_BUG_ON(sizeof(union afs_dirent) != 32); | 497 | BUILD_BUG_ON(sizeof(union afs_xdr_dirent) != 32); |
498 | 498 | ||
499 | if (cookie->name.len != nlen || | 499 | if (cookie->name.len != nlen || |
500 | memcmp(cookie->name.name, name, nlen) != 0) { | 500 | memcmp(cookie->name.name, name, nlen) != 0) { |
@@ -562,8 +562,8 @@ static int afs_lookup_filldir(struct dir_context *ctx, const char *name, | |||
562 | (unsigned long long) ino, dtype); | 562 | (unsigned long long) ino, dtype); |
563 | 563 | ||
564 | /* insanity checks first */ | 564 | /* insanity checks first */ |
565 | BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048); | 565 | BUILD_BUG_ON(sizeof(union afs_xdr_dir_block) != 2048); |
566 | BUILD_BUG_ON(sizeof(union afs_dirent) != 32); | 566 | BUILD_BUG_ON(sizeof(union afs_xdr_dirent) != 32); |
567 | 567 | ||
568 | if (cookie->found) { | 568 | if (cookie->found) { |
569 | if (cookie->nr_fids < 50) { | 569 | if (cookie->nr_fids < 50) { |
diff --git a/fs/afs/xdr_fs.h b/fs/afs/xdr_fs.h index 63e87ccbb55b..aa21f3068d52 100644 --- a/fs/afs/xdr_fs.h +++ b/fs/afs/xdr_fs.h | |||
@@ -51,53 +51,53 @@ struct afs_xdr_AFSFetchStatus { | |||
51 | /* | 51 | /* |
52 | * Directory entry structure. | 52 | * Directory entry structure. |
53 | */ | 53 | */ |
54 | union afs_dirent { | 54 | union afs_xdr_dirent { |
55 | struct { | 55 | struct { |
56 | uint8_t valid; | 56 | u8 valid; |
57 | uint8_t unused[1]; | 57 | u8 unused[1]; |
58 | __be16 hash_next; | 58 | __be16 hash_next; |
59 | __be32 vnode; | 59 | __be32 vnode; |
60 | __be32 unique; | 60 | __be32 unique; |
61 | uint8_t name[16]; | 61 | u8 name[16]; |
62 | uint8_t overflow[4]; /* if any char of the name (inc | 62 | u8 overflow[4]; /* if any char of the name (inc |
63 | * NUL) reaches here, consume | 63 | * NUL) reaches here, consume |
64 | * the next dirent too */ | 64 | * the next dirent too */ |
65 | } u; | 65 | } u; |
66 | uint8_t extended_name[32]; | 66 | u8 extended_name[32]; |
67 | }; | 67 | } __packed; |
68 | 68 | ||
69 | /* | 69 | /* |
70 | * Directory page header (one at the beginning of every 2048-byte chunk). | 70 | * Directory block header (one at the beginning of every 2048-byte block). |
71 | */ | 71 | */ |
72 | struct afs_dir_pagehdr { | 72 | struct afs_xdr_dir_hdr { |
73 | __be16 npages; | 73 | __be16 npages; |
74 | __be16 magic; | 74 | __be16 magic; |
75 | #define AFS_DIR_MAGIC htons(1234) | 75 | #define AFS_DIR_MAGIC htons(1234) |
76 | uint8_t reserved; | 76 | u8 reserved; |
77 | uint8_t bitmap[8]; | 77 | u8 bitmap[8]; |
78 | uint8_t pad[19]; | 78 | u8 pad[19]; |
79 | }; | 79 | } __packed; |
80 | 80 | ||
81 | /* | 81 | /* |
82 | * Directory block layout | 82 | * Directory block layout |
83 | */ | 83 | */ |
84 | union afs_dir_block { | 84 | union afs_xdr_dir_block { |
85 | struct afs_dir_pagehdr pagehdr; | 85 | struct afs_xdr_dir_hdr hdr; |
86 | 86 | ||
87 | struct { | 87 | struct { |
88 | struct afs_dir_pagehdr pagehdr; | 88 | struct afs_xdr_dir_hdr hdr; |
89 | uint8_t alloc_ctrs[AFS_DIR_MAX_BLOCKS]; | 89 | u8 alloc_ctrs[AFS_DIR_MAX_BLOCKS]; |
90 | __be16 hashtable[AFS_DIR_HASHTBL_SIZE]; | 90 | __be16 hashtable[AFS_DIR_HASHTBL_SIZE]; |
91 | } hdr; | 91 | } meta; |
92 | 92 | ||
93 | union afs_dirent dirents[AFS_DIR_SLOTS_PER_BLOCK]; | 93 | union afs_xdr_dirent dirents[AFS_DIR_SLOTS_PER_BLOCK]; |
94 | }; | 94 | } __packed; |
95 | 95 | ||
96 | /* | 96 | /* |
97 | * Directory layout on a linux VM page. | 97 | * Directory layout on a linux VM page. |
98 | */ | 98 | */ |
99 | struct afs_dir_page { | 99 | struct afs_xdr_dir_page { |
100 | union afs_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE]; | 100 | union afs_xdr_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE]; |
101 | }; | 101 | }; |
102 | 102 | ||
103 | #endif /* XDR_FS_H */ | 103 | #endif /* XDR_FS_H */ |