Skip to content

Commit 8cfc0c7

Browse files
jtlaytonidryomov
authored andcommitted
ceph: properly handle statfs on multifs setups
ceph_statfs currently stuffs the cluster fsid into the f_fsid field. This was fine when we only had a single filesystem per cluster, but now that we have multiples we need to use something that will vary between them. Change ceph_statfs to xor each 32-bit chunk of the fsid (aka cluster id) into the lower bits of the statfs->f_fsid. Change the lower bits to hold the fscid (filesystem ID within the cluster). That should give us a value that is guaranteed to be unique between filesystems within a cluster, and should minimize the chance of collisions between mounts of different clusters. URL: https://tracker.ceph.com/issues/52812 Reported-by: Sachin Prabhu <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Reviewed-by: Xiubo Li <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 631ed4b commit 8cfc0c7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

fs/ceph/super.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
5252
struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry));
5353
struct ceph_mon_client *monc = &fsc->client->monc;
5454
struct ceph_statfs st;
55-
u64 fsid;
56-
int err;
55+
int i, err;
5756
u64 data_pool;
5857

5958
if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
@@ -99,12 +98,14 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
9998
buf->f_namelen = NAME_MAX;
10099

101100
/* Must convert the fsid, for consistent values across arches */
101+
buf->f_fsid.val[0] = 0;
102102
mutex_lock(&monc->mutex);
103-
fsid = le64_to_cpu(*(__le64 *)(&monc->monmap->fsid)) ^
104-
le64_to_cpu(*((__le64 *)&monc->monmap->fsid + 1));
103+
for (i = 0 ; i < sizeof(monc->monmap->fsid) / sizeof(__le32) ; ++i)
104+
buf->f_fsid.val[0] ^= le32_to_cpu(((__le32 *)&monc->monmap->fsid)[i]);
105105
mutex_unlock(&monc->mutex);
106106

107-
buf->f_fsid = u64_to_fsid(fsid);
107+
/* fold the fs_cluster_id into the upper bits */
108+
buf->f_fsid.val[1] = monc->fs_cluster_id;
108109

109110
return 0;
110111
}

0 commit comments

Comments
 (0)