ceph: fix incorrectly showing the .snap size for stat
PATCH v2 1/1 ceph: fix incorrectly showing the .snap size for stat
From: Xiubo Li <[email protected]>
We should set the 'stat->size' to the real number of snapshots for snapdirs.
URL: https://tracker.ceph.com/issues/57342
--- fs/ceph/inode.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-)
fs/ceph/inode.c +66 -2
@@ -2705,6 +2705,52 @@ static int statx_to_caps(u32 want, umode_t mode)return mask; } +static struct inode *ceph_get_snap_parent (struct inode *inode) +{ +struct super_block *sb = inode->i_sb; +struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (sb); +struct ceph_mds_request *req; +struct ceph_vino vino = { + .ino =ceph_ino (inode), + .snap =CEPH_NOSNAP , + }; +struct inode *parent; +int mask; +int err; + +if (ceph_vino_is_reserved (vino)) +return ERR_PTR (-ESTALE ); + + parent =ceph_find_inode (sb, vino); +if (likely (parent)) { +if (ceph_inode_is_shutdown (parent)) { +iput (parent); +return ERR_PTR (-ESTALE ); + } +return parent; + } + + req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_LOOKUPINO , +USE_ANY_MDS ); +if (IS_ERR (req)) +return ERR_CAST (req); + + mask =CEPH_STAT_CAP_INODE ; +if (ceph_security_xattr_wanted (d_inode (sb->s_root))) + mask |=CEPH_CAP_XATTR_SHARED ; + req->r_args.lookupino.mask =cpu_to_le32 (mask); + req->r_ino1 = vino; + req->r_num_caps =1 ; + err =ceph_mdsc_do_request (mdsc,NULL , req); +if (err <0 ) +return ERR_PTR (err); + parent = req->r_target_inode; +if (!parent) +return ERR_PTR (-ESTALE ); +ihold (parent); +return parent; +} +/* * Get all the attributes. If we have sufficient caps for the requested attrs, * then we can avoid talking to the MDS at all.
@@ -2748,10 +2794,28 @@ int ceph_getattr(struct user_namespace *mnt_userns, const struct path *path,if (S_ISDIR (inode->i_mode)) {if (ceph_test_mount_opt (ceph_sb_to_client (inode->i_sb), -RBYTES )) +RBYTES )) { stat->size = ci->i_rbytes; -else + }else if (ceph_snap (inode) ==CEPH_SNAPDIR ) { +struct inode *parent =ceph_get_snap_parent (inode); +struct ceph_inode_info *pci; +struct ceph_snap_realm *realm; + +if (!parent) +return PTR_ERR (parent); + + pci =ceph_inode (parent); +spin_lock (&pci->i_ceph_lock); + realm = pci->i_snap_realm; +if (realm) + stat->size = realm->num_snaps; +else + stat->size =0 ; +spin_unlock (&pci->i_ceph_lock); +iput (parent); + }else { stat->size = ci->i_files + ci->i_subdirs; + } stat->blocks =0 ; stat->blksize =65536 ;/*
Signature · 1 line
2.36.0.rc1
Quoted 54 lines · On Wed, Aug 31, 2022 at 04:02:57PM +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
We should set the '
stat->size' to the real number of snapshots for snapdirs.URL: https://tracker.ceph.com/issues/57342
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/inode.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-)fs/ceph/inode.c +35
-0@@ -2705,6 +2705,52 @@ static int statx_to_caps(u32 want, umode_t mode)return mask; } +static struct inode *ceph_get_snap_parent (struct inode *inode) +{ +struct super_block *sb = inode->i_sb; +struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (sb); +struct ceph_mds_request *req; +struct ceph_vino vino = { + .ino =ceph_ino (inode), + .snap =CEPH_NOSNAP , + }; +struct inode *parent; +int mask; +int err; + +if (ceph_vino_is_reserved (vino)) +return ERR_PTR (-ESTALE ); + + parent =ceph_find_inode (sb, vino); +if (likely (parent)) { +if (ceph_inode_is_shutdown (parent)) { +iput (parent); +return ERR_PTR (-ESTALE ); + } +return parent; + } + + req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_LOOKUPINO , +USE_ANY_MDS ); +if (IS_ERR (req)) +return ERR_CAST (req); + + mask =CEPH_STAT_CAP_INODE ; +if (ceph_security_xattr_wanted (d_inode (sb->s_root))) + mask |=CEPH_CAP_XATTR_SHARED ; + req->r_args.lookupino.mask =cpu_to_le32 (mask); + req->r_ino1 = vino;
fs/ceph/inode.c static int statx_to_caps(u32 want, umode_t mode) · line 2752
Quoted 10 lines
fs/ceph/inode.c +10
-0+ req->r_num_caps =1 ; + err =ceph_mdsc_do_request (mdsc,NULL , req); +if (err <0 ) +return ERR_PTR (err); + parent = req->r_target_inode; +if (!parent) +return ERR_PTR (-ESTALE ); +ihold (parent); +return parent; +}
Can't we simply re-use __lookup_inode() instead of duplicating all this code?
(Also: is there a similar fix for the fuse client?)
Cheers,
--
Luís
Quoted 38 lines
fs/ceph/inode.c +21
-2+/* * Get all the attributes. If we have sufficient caps for the requested attrs, * then we can avoid talking to the MDS at all. @@ -2748,10 +2794,28 @@ int ceph_getattr(struct user_namespace *mnt_userns, const struct path *path,if (S_ISDIR (inode->i_mode)) {if (ceph_test_mount_opt (ceph_sb_to_client (inode->i_sb), -RBYTES )) +RBYTES )) { stat->size = ci->i_rbytes; -else + }else if (ceph_snap (inode) ==CEPH_SNAPDIR ) { +struct inode *parent =ceph_get_snap_parent (inode); +struct ceph_inode_info *pci; +struct ceph_snap_realm *realm; + +if (!parent) +return PTR_ERR (parent); + + pci =ceph_inode (parent); +spin_lock (&pci->i_ceph_lock); + realm = pci->i_snap_realm; +if (realm) + stat->size = realm->num_snaps; +else + stat->size =0 ; +spin_unlock (&pci->i_ceph_lock); +iput (parent); + }else { stat->size = ci->i_files + ci->i_subdirs; + } stat->blocks =0 ; stat->blksize =65536 ;/* Signature · 1 line
2.36.0.rc1
Quoted 59 lines · Luís Henriques
Quoted 58 lines · On Wed, Aug 31, 2022 at 04:02:57PM +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
We should set the '
stat->size' to the real number of snapshots for snapdirs.URL: https://tracker.ceph.com/issues/57342
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/inode.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-)fs/ceph/inode.c +39
-0@@ -2705,6 +2705,52 @@ static int statx_to_caps(u32 want, umode_t mode)return mask; } +static struct inode *ceph_get_snap_parent (struct inode *inode) +{ +struct super_block *sb = inode->i_sb; +struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (sb); +struct ceph_mds_request *req; +struct ceph_vino vino = { + .ino =ceph_ino (inode), + .snap =CEPH_NOSNAP , + }; +struct inode *parent; +int mask; +int err; + +if (ceph_vino_is_reserved (vino)) +return ERR_PTR (-ESTALE ); + + parent =ceph_find_inode (sb, vino); +if (likely (parent)) { +if (ceph_inode_is_shutdown (parent)) { +iput (parent); +return ERR_PTR (-ESTALE ); + } +return parent; + } + + req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_LOOKUPINO , +USE_ANY_MDS ); +if (IS_ERR (req)) +return ERR_CAST (req); + + mask =CEPH_STAT_CAP_INODE ; +if (ceph_security_xattr_wanted (d_inode (sb->s_root))) + mask |=CEPH_CAP_XATTR_SHARED ; + req->r_args.lookupino.mask =cpu_to_le32 (mask); + req->r_ino1 = vino; + req->r_num_caps =1 ; + err =ceph_mdsc_do_request (mdsc,NULL , req); +if (err <0 ) +return ERR_PTR (err);
Quoted 8 lines
fs/ceph/inode.c static int statx_to_caps(u32 want, umode_t mode) · line 2752
Quoted 6 lines
fs/ceph/inode.c +6
-0+ parent = req->r_target_inode; +if (!parent) +return ERR_PTR (-ESTALE ); +ihold (parent); +return parent; +}Can't we simply re-use
__lookup_inode()instead of duplicating all this code?
It seems working.
Let me check more about that.
Quoted 1 line
(Also: is there a similar fix for the fuse client?)
Yeah, I have raised one PR for that already.
Thanks Luis!
Quoted 42 lines
Cheers,
--
LuísQuoted 38 lines
fs/ceph/inode.c +21
-2+/* * Get all the attributes. If we have sufficient caps for the requested attrs, * then we can avoid talking to the MDS at all. @@ -2748,10 +2794,28 @@ int ceph_getattr(struct user_namespace *mnt_userns, const struct path *path,if (S_ISDIR (inode->i_mode)) {if (ceph_test_mount_opt (ceph_sb_to_client (inode->i_sb), -RBYTES )) +RBYTES )) { stat->size = ci->i_rbytes; -else + }else if (ceph_snap (inode) ==CEPH_SNAPDIR ) { +struct inode *parent =ceph_get_snap_parent (inode); +struct ceph_inode_info *pci; +struct ceph_snap_realm *realm; + +if (!parent) +return PTR_ERR (parent); + + pci =ceph_inode (parent); +spin_lock (&pci->i_ceph_lock); + realm = pci->i_snap_realm; +if (realm) + stat->size = realm->num_snaps; +else + stat->size =0 ; +spin_unlock (&pci->i_ceph_lock); +iput (parent); + }else { stat->size = ci->i_files + ci->i_subdirs; + } stat->blocks =0 ; stat->blksize =65536 ;/* Signature · 1 line
2.36.0.rc1