Skip to content

Commit d50eb28

Browse files
dubeykoidryomov
authored andcommitted
ceph: cleanup hardcoded constants of file handle size
The ceph/export.c contains very confusing logic of file handle size calculation based on hardcoded values. This patch makes the cleanup of this logic by means of introduction the named constants. Signed-off-by: Viacheslav Dubeyko <[email protected]> Reviewed-by: Alex Markuze <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 0abd879 commit d50eb28

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

fs/ceph/export.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ struct ceph_nfs_snapfh {
3333
u32 hash;
3434
} __attribute__ ((packed));
3535

36+
#define BYTES_PER_U32 (sizeof(u32))
37+
#define CEPH_FH_BASIC_SIZE \
38+
(sizeof(struct ceph_nfs_fh) / BYTES_PER_U32)
39+
#define CEPH_FH_WITH_PARENT_SIZE \
40+
(sizeof(struct ceph_nfs_confh) / BYTES_PER_U32)
41+
#define CEPH_FH_SNAPPED_INODE_SIZE \
42+
(sizeof(struct ceph_nfs_snapfh) / BYTES_PER_U32)
43+
3644
static int ceph_encode_snapfh(struct inode *inode, u32 *rawfh, int *max_len,
3745
struct inode *parent_inode)
3846
{
3947
struct ceph_client *cl = ceph_inode_to_client(inode);
40-
static const int snap_handle_length =
41-
sizeof(struct ceph_nfs_snapfh) >> 2;
48+
static const int snap_handle_length = CEPH_FH_SNAPPED_INODE_SIZE;
4249
struct ceph_nfs_snapfh *sfh = (void *)rawfh;
4350
u64 snapid = ceph_snap(inode);
4451
int ret;
@@ -88,10 +95,8 @@ static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,
8895
struct inode *parent_inode)
8996
{
9097
struct ceph_client *cl = ceph_inode_to_client(inode);
91-
static const int handle_length =
92-
sizeof(struct ceph_nfs_fh) >> 2;
93-
static const int connected_handle_length =
94-
sizeof(struct ceph_nfs_confh) >> 2;
98+
static const int handle_length = CEPH_FH_BASIC_SIZE;
99+
static const int connected_handle_length = CEPH_FH_WITH_PARENT_SIZE;
95100
int type;
96101

97102
if (ceph_snap(inode) != CEPH_NOSNAP)
@@ -308,7 +313,7 @@ static struct dentry *ceph_fh_to_dentry(struct super_block *sb,
308313
if (fh_type != FILEID_INO32_GEN &&
309314
fh_type != FILEID_INO32_GEN_PARENT)
310315
return NULL;
311-
if (fh_len < sizeof(*fh) / 4)
316+
if (fh_len < sizeof(*fh) / BYTES_PER_U32)
312317
return NULL;
313318

314319
doutc(fsc->client, "%llx\n", fh->ino);
@@ -427,7 +432,7 @@ static struct dentry *ceph_fh_to_parent(struct super_block *sb,
427432

428433
if (fh_type != FILEID_INO32_GEN_PARENT)
429434
return NULL;
430-
if (fh_len < sizeof(*cfh) / 4)
435+
if (fh_len < sizeof(*cfh) / BYTES_PER_U32)
431436
return NULL;
432437

433438
doutc(fsc->client, "%llx\n", cfh->parent_ino);

0 commit comments

Comments
 (0)