diff mbox series

[2/2] ceph: add CEPH_IOC_GET_FS_CLIENT_IDS ioctl cmd support

Message ID 20201105023703.735882-3-xiubli@redhat.com
State New
Headers show
Series ceph: add _IDS ioctl cmd and status debug file support | expand

Commit Message

Xiubo Li Nov. 5, 2020, 2:37 a.m. UTC
From: Xiubo Li <xiubli@redhat.com>

This ioctl will return the dedicated fs and client IDs back to
userspace. With this we can easily know which mountpoint the file
blongs to and also they can help locate the debugfs path quickly.

URL: https://tracker.ceph.com/issues/48124
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
 fs/ceph/ioctl.c | 22 ++++++++++++++++++++++
 fs/ceph/ioctl.h | 15 +++++++++++++++
 2 files changed, 37 insertions(+)

Comments

Ilya Dryomov Nov. 10, 2020, 8:05 a.m. UTC | #1
On Thu, Nov 5, 2020 at 3:37 AM <xiubli@redhat.com> wrote:
>

> From: Xiubo Li <xiubli@redhat.com>

>

> This ioctl will return the dedicated fs and client IDs back to

> userspace. With this we can easily know which mountpoint the file

> blongs to and also they can help locate the debugfs path quickly.


belongs

>

> URL: https://tracker.ceph.com/issues/48124

> Signed-off-by: Xiubo Li <xiubli@redhat.com>

> ---

>  fs/ceph/ioctl.c | 22 ++++++++++++++++++++++

>  fs/ceph/ioctl.h | 15 +++++++++++++++

>  2 files changed, 37 insertions(+)

>

> diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c

> index 6e061bf62ad4..2498a1df132e 100644

> --- a/fs/ceph/ioctl.c

> +++ b/fs/ceph/ioctl.c

> @@ -268,6 +268,25 @@ static long ceph_ioctl_syncio(struct file *file)

>         return 0;

>  }

>

> +static long ceph_ioctl_get_client_id(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 fs_client_ids ids;

> +       char fsid[40];

> +

> +       snprintf(fsid, sizeof(fsid), "%pU", &fsc->client->fsid);

> +       memcpy(ids.fsid, fsid, sizeof(fsid));

> +

> +       ids.global_id = fsc->client->monc.auth->global_id;


Why is fsid returned in text and global_id in binary?  I get that the
initial use case is constructing "<fsid>.client<global_id>" string, but
it's probably better to stick to binary.

Use ceph_client_gid() for getting global_id.

> +

> +       /* 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 +308,9 @@ 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_FS_CLIENT_IDS:

> +               return ceph_ioctl_get_client_id(file, (void __user *)arg);

>         }

>

>         return -ENOTTY;

> diff --git a/fs/ceph/ioctl.h b/fs/ceph/ioctl.h

> index 51f7f1d39a94..59c7479e77b2 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_FS_CLIENT_IDS - get the fs and client ids

> + *

> + * This ioctl will return the dedicated fs and client IDs back to


The "fsid" you are capturing is really a cluster id, which may be home
to multiple CephFS filesystems.  Referring to it as a "dedicated fs ID"
is misleading.

Thanks,

                Ilya
Xiubo Li Nov. 10, 2020, 8:54 a.m. UTC | #2
On 2020/11/10 16:05, Ilya Dryomov wrote:
> On Thu, Nov 5, 2020 at 3:37 AM <xiubli@redhat.com> wrote:

>> From: Xiubo Li <xiubli@redhat.com>

>>

>> This ioctl will return the dedicated fs and client IDs back to

>> userspace. With this we can easily know which mountpoint the file

>> blongs to and also they can help locate the debugfs path quickly.

> belongs

Will fix it.
>

>> URL: https://tracker.ceph.com/issues/48124

>> Signed-off-by: Xiubo Li <xiubli@redhat.com>

>> ---

>>   fs/ceph/ioctl.c | 22 ++++++++++++++++++++++

>>   fs/ceph/ioctl.h | 15 +++++++++++++++

>>   2 files changed, 37 insertions(+)

>>

>> diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c

>> index 6e061bf62ad4..2498a1df132e 100644

>> --- a/fs/ceph/ioctl.c

>> +++ b/fs/ceph/ioctl.c

>> @@ -268,6 +268,25 @@ static long ceph_ioctl_syncio(struct file *file)

>>          return 0;

>>   }

>>

>> +static long ceph_ioctl_get_client_id(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 fs_client_ids ids;

>> +       char fsid[40];

>> +

>> +       snprintf(fsid, sizeof(fsid), "%pU", &fsc->client->fsid);

>> +       memcpy(ids.fsid, fsid, sizeof(fsid));

>> +

>> +       ids.global_id = fsc->client->monc.auth->global_id;

> Why is fsid returned in text and global_id in binary?  I get that the

> initial use case is constructing "<fsid>.client<global_id>" string, but

> it's probably better to stick to binary.


Checked the ceph_debugfs_client_init() and rbd.c, they are both 
returning in text like this:

snprintf(name, sizeof(name), "%pU.client%lld", &client->fsid, 
client->monc.auth->global_id);

So let's make it the same with the rbd.c.


> Use ceph_client_gid() for getting global_id.

>

>> +

>> +       /* 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 +308,9 @@ 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_FS_CLIENT_IDS:

>> +               return ceph_ioctl_get_client_id(file, (void __user *)arg);

>>          }

>>

>>          return -ENOTTY;

>> diff --git a/fs/ceph/ioctl.h b/fs/ceph/ioctl.h

>> index 51f7f1d39a94..59c7479e77b2 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_FS_CLIENT_IDS - get the fs and client ids

>> + *

>> + * This ioctl will return the dedicated fs and client IDs back to

> The "fsid" you are capturing is really a cluster id, which may be home

> to multiple CephFS filesystems.  Referring to it as a "dedicated fs ID"

> is misleading.


Yeah, it is, will fix it.

Thanks.

>

> Thanks,

>

>                  Ilya

>
diff mbox series

Patch

diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
index 6e061bf62ad4..2498a1df132e 100644
--- a/fs/ceph/ioctl.c
+++ b/fs/ceph/ioctl.c
@@ -268,6 +268,25 @@  static long ceph_ioctl_syncio(struct file *file)
 	return 0;
 }
 
+static long ceph_ioctl_get_client_id(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 fs_client_ids ids;
+	char fsid[40];
+
+	snprintf(fsid, sizeof(fsid), "%pU", &fsc->client->fsid);
+	memcpy(ids.fsid, fsid, sizeof(fsid));
+
+	ids.global_id = fsc->client->monc.auth->global_id;
+
+	/* 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 +308,9 @@  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_FS_CLIENT_IDS:
+		return ceph_ioctl_get_client_id(file, (void __user *)arg);
 	}
 
 	return -ENOTTY;
diff --git a/fs/ceph/ioctl.h b/fs/ceph/ioctl.h
index 51f7f1d39a94..59c7479e77b2 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_FS_CLIENT_IDS - get the fs and client ids
+ *
+ * This ioctl will return the dedicated fs and client IDs back to
+ * userspace. With this we can easily know which mountpoint the file
+ * blongs to and also they can help locate the debugfs path quickly.
+ */
+
+struct fs_client_ids {
+	char fsid[40];
+	__u64 global_id;
+};
+#define CEPH_IOC_GET_FS_CLIENT_IDS _IOR(CEPH_IOCTL_MAGIC, 6, \
+					struct fs_client_ids)
+
 #endif