On Tue, 2020-11-10 at 21:25 +0800, Xiubo Li wrote: > On 2020/11/10 20:24, Jeff Layton wrote: > > On Tue, 2020-11-10 at 18:57 +0800, xiubli@xxxxxxxxxx wrote: > > > From: Xiubo Li <xiubli@xxxxxxxxxx> > > > > > > This ioctl will return the cluster and client ids back to userspace. > > > With this we can easily know which mountpoint the file belongs to and > > > also they can help locate the debugfs path quickly. > > > > > > URL: https://tracker.ceph.com/issues/48124 > > > Signed-off-by: Xiubo Li <xiubli@xxxxxxxxxx> > > > --- > > > fs/ceph/ioctl.c | 23 +++++++++++++++++++++++ > > > fs/ceph/ioctl.h | 15 +++++++++++++++ > > > 2 files changed, 38 insertions(+) > > > > > I know I opened this bug and suggested an ioctl for this, but I think > > that this may be better presented as new vxattrs. Driving ioctls from > > scripts is difficult (in particular). An xattr is easier for them to > > deal with. Maybe: > > > > ceph.clusterid > > ceph.clientid > > How about : > > [root@lxbceph1 kcephfs]# getfattr -n ceph.local.clusterid file > # file: file > ceph.local.clusterid="6ff21dc9-36b0-45a9-bec2-75aeaf0414cf" > > [root@lxbceph1 kcephfs]# getfattr -n ceph.local.clientid file > # file: file > ceph.local.clientid="client4360" > > ?? > What does "local" signify in these names? > > > > ...or you could even make one that gives you the same format as the > > dirnames in /sys/kernel/debug/ceph. > > > > > diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c > > > index 6e061bf62ad4..a4b69c1026ce 100644 > > > --- a/fs/ceph/ioctl.c > > > +++ b/fs/ceph/ioctl.c > > > @@ -268,6 +268,27 @@ static long ceph_ioctl_syncio(struct file *file) > > > return 0; > > > } > > > > > > > > > > > > > > > +/* > > > + * Return the cluster and client ids > > > + */ > > > +static long ceph_ioctl_get_fs_ids(struct file *file, void __user *arg) > > > +{ > > > + struct inode *inode = file_inode(file); > > > + struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb); > > > + struct cluster_client_ids ids; > > > + > > > + snprintf(ids.cluster_id, sizeof(ids.cluster_id), "%pU", > > > + &fsc->client->fsid); > > > + snprintf(ids.client_id, sizeof(ids.client_id), "client%lld", > > > + ceph_client_gid(fsc->client)); > > > + > > > + /* send result back to user */ > > > + if (copy_to_user(arg, &ids, sizeof(ids))) > > > + return -EFAULT; > > > + > > > + return 0; > > > +} > > > + > > > long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > > > { > > > dout("ioctl file %p cmd %u arg %lu\n", file, cmd, arg); > > > @@ -289,6 +310,8 @@ long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > > > > > > > > > > > > > > > > > > > > > > > > case CEPH_IOC_SYNCIO: > > > return ceph_ioctl_syncio(file); > > > + case CEPH_IOC_GET_CLUSTER_AND_CLIENT_IDS: > > > + return ceph_ioctl_get_fs_ids(file, (void __user *)arg); > > > } > > > > > > > > > > > > > > > > > > > > > > > > return -ENOTTY; > > > diff --git a/fs/ceph/ioctl.h b/fs/ceph/ioctl.h > > > index 51f7f1d39a94..9879d58854fb 100644 > > > --- a/fs/ceph/ioctl.h > > > +++ b/fs/ceph/ioctl.h > > > @@ -98,4 +98,19 @@ struct ceph_ioctl_dataloc { > > > */ > > > #define CEPH_IOC_SYNCIO _IO(CEPH_IOCTL_MAGIC, 5) > > > > > > > > > > > > > > > > > > > > > > > > +/* > > > + * CEPH_IOC_GET_CLUSTER_AND_CLIENT_IDS - get the cluster and client ids > > > + * > > > + * This ioctl will return the cluster and client ids back to user space. > > > + * With this we can easily know which mountpoint the file belongs to and > > > + * also they can help locate the debugfs path quickly. > > > + */ > > > + > > > +struct cluster_client_ids { > > > + char cluster_id[40]; > > > + char client_id[24]; > > > +}; > > > +#define CEPH_IOC_GET_CLUSTER_AND_CLIENT_IDS _IOR(CEPH_IOCTL_MAGIC, 6, \ > > > + struct cluster_client_ids) > > > + > > > #endif > > -- Jeff Layton <jlayton@xxxxxxxxxx>