Message ID | 9fca0011d2ac24f7b84990db1c4af5eaa60da876.1696431315.git.anand.jain@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: sysfs and unsupported temp-fsid features for clones | expand |
On Wed, Oct 04, 2023 at 11:00:27PM +0800, Anand Jain wrote: > This adds sysfs objects to indicate temp_fsid feature support and > its status. > > /sys/fs/btrfs/features/temp_fsid > /sys/fs/btrfs/<UUID>/temp_fsid > > For example: > > Consider two cloned and mounted devices. > > $ blkid /dev/sdc[1-2] > /dev/sdc1: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. > /dev/sdc2: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. > > One gets actual fsid, and the other gets the temp_fsid when > mounted. > > $ btrfs filesystem show -m > Label: none uuid: 509ad44b-ad2a-4a8a-bc8d-fe69db7220d5 > Total devices 1 FS bytes used 54.14MiB > devid 1 size 300.00MiB used 144.00MiB path /dev/sdc1 > > Label: none uuid: 33bad74e-c91b-43a5-aef8-b3cab97ae63a > Total devices 1 FS bytes used 54.14MiB > devid 1 size 300.00MiB used 144.00MiB path /dev/sdc2 > > Their sysfs as below. > > $ cat /sys/fs/btrfs/features/temp_fsid > 0 > > $ cat /sys/fs/btrfs/509ad44b-ad2a-4a8a-bc8d-fe69db7220d5/temp_fsid > 0 > > $ cat /sys/fs/btrfs/33bad74e-c91b-43a5-aef8-b3cab97ae63a/temp_fsid > 1 So the fsid used for the directory is always the new one, is there a way to read which is the original filesystem's fsid? In this case it would be the 509ad44b-... We could print it in that file instead of '1', though it could be confusing that it's not the temp_fsid but the original one, file name mismatches the contents on first look. > Signed-off-by: Anand Jain <anand.jain@oracle.com> > --- > fs/btrfs/sysfs.c | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c > index e07be193323a..7f9a4790e013 100644 > --- a/fs/btrfs/sysfs.c > +++ b/fs/btrfs/sysfs.c > @@ -425,6 +425,15 @@ static ssize_t acl_show(struct kobject *kobj, struct kobj_attribute *a, char *bu > } > BTRFS_ATTR(static_feature, acl, acl_show); > > +static ssize_t temp_fsid_supported_show(struct kobject *kobj, > + struct kobj_attribute *a, char *buf) > +{ > + int ret = 0; > + > + return sysfs_emit(buf, "%d\n", ret); This can be return sysfs_emit(buf, "0\n");
On 10/6/23 22:55, David Sterba wrote: > On Wed, Oct 04, 2023 at 11:00:27PM +0800, Anand Jain wrote: >> This adds sysfs objects to indicate temp_fsid feature support and >> its status. >> >> /sys/fs/btrfs/features/temp_fsid >> /sys/fs/btrfs/<UUID>/temp_fsid >> >> For example: >> >> Consider two cloned and mounted devices. >> >> $ blkid /dev/sdc[1-2] >> /dev/sdc1: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. >> /dev/sdc2: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. >> >> One gets actual fsid, and the other gets the temp_fsid when >> mounted. >> >> $ btrfs filesystem show -m >> Label: none uuid: 509ad44b-ad2a-4a8a-bc8d-fe69db7220d5 >> Total devices 1 FS bytes used 54.14MiB >> devid 1 size 300.00MiB used 144.00MiB path /dev/sdc1 >> >> Label: none uuid: 33bad74e-c91b-43a5-aef8-b3cab97ae63a >> Total devices 1 FS bytes used 54.14MiB >> devid 1 size 300.00MiB used 144.00MiB path /dev/sdc2 >> >> Their sysfs as below. >> >> $ cat /sys/fs/btrfs/features/temp_fsid >> 0 >> >> $ cat /sys/fs/btrfs/509ad44b-ad2a-4a8a-bc8d-fe69db7220d5/temp_fsid >> 0 >> >> $ cat /sys/fs/btrfs/33bad74e-c91b-43a5-aef8-b3cab97ae63a/temp_fsid >> 1 > > So the fsid used for the directory is always the new one, is there a way > to read which is the original filesystem's fsid? In this case it would > be the 509ad44b-... We could print it in that file instead of '1', > though it could be confusing that it's not the temp_fsid but the > original one, file name mismatches the contents on first look. Instead, can we emit 'fsid' in another kobject altogether? Furthermore, we also have a 'metadata_uuid' kobject. Here is how they relate. 1. normally: $ cat /sys/fs/btrfs/<meta-fsid>/fsid <meta-fsid> $ cat /sys/fs/btrfs/<meta-fsid>/metadata_uuid <meta-fsid> 2. metadata-uuid flag is set: $ cat /sys/fs/btrfs/<sb-fsid>/fsid <sb-fsid> $ cat /sys/fs/btrfs/<sb-fsid>/metadata_uuid <meta-fsid> 3. normal + temp-fsid: $ cat /sys/fs/btrfs/<temp-fsid>/fsid <meta-fsid> $ cat /sys/fs/btrfs/<temp-fsid>/metadata_uuid <meta-fsid> 4. metadata-uuid flag is set + temp-fsid: $ cat /sys/fs/btrfs/<temp-fsid>/fsid <sb-fsid> $ cat /sys/fs/btrfs/<temp-fsid>/metadata_uuid <meta-fsid> > >> Signed-off-by: Anand Jain <anand.jain@oracle.com> >> --- >> fs/btrfs/sysfs.c | 20 ++++++++++++++++++++ >> 1 file changed, 20 insertions(+) >> >> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c >> index e07be193323a..7f9a4790e013 100644 >> --- a/fs/btrfs/sysfs.c >> +++ b/fs/btrfs/sysfs.c >> @@ -425,6 +425,15 @@ static ssize_t acl_show(struct kobject *kobj, struct kobj_attribute *a, char *bu >> } >> BTRFS_ATTR(static_feature, acl, acl_show); >> >> +static ssize_t temp_fsid_supported_show(struct kobject *kobj, >> + struct kobj_attribute *a, char *buf) >> +{ >> + int ret = 0; >> + >> + return sysfs_emit(buf, "%d\n", ret); > > This can be > > return sysfs_emit(buf, "0\n"); Changes in the misc-next looks better. Thanks, Anand
On 10/7/23 17:12, Anand Jain wrote: > > > On 10/6/23 22:55, David Sterba wrote: >> On Wed, Oct 04, 2023 at 11:00:27PM +0800, Anand Jain wrote: >>> This adds sysfs objects to indicate temp_fsid feature support and >>> its status. >>> >>> /sys/fs/btrfs/features/temp_fsid >>> /sys/fs/btrfs/<UUID>/temp_fsid >>> >>> For example: >>> >>> Consider two cloned and mounted devices. >>> >>> $ blkid /dev/sdc[1-2] >>> /dev/sdc1: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. >>> /dev/sdc2: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. >>> >>> One gets actual fsid, and the other gets the temp_fsid when >>> mounted. >>> >>> $ btrfs filesystem show -m >>> Label: none uuid: 509ad44b-ad2a-4a8a-bc8d-fe69db7220d5 >>> Total devices 1 FS bytes used 54.14MiB >>> devid 1 size 300.00MiB used 144.00MiB path /dev/sdc1 >>> >>> Label: none uuid: 33bad74e-c91b-43a5-aef8-b3cab97ae63a >>> Total devices 1 FS bytes used 54.14MiB >>> devid 1 size 300.00MiB used 144.00MiB path /dev/sdc2 >>> >>> Their sysfs as below. >>> >>> $ cat /sys/fs/btrfs/features/temp_fsid >>> 0 >>> >>> $ cat /sys/fs/btrfs/509ad44b-ad2a-4a8a-bc8d-fe69db7220d5/temp_fsid >>> 0 >>> >>> $ cat /sys/fs/btrfs/33bad74e-c91b-43a5-aef8-b3cab97ae63a/temp_fsid >>> 1 >> >> So the fsid used for the directory is always the new one, is there a way >> to read which is the original filesystem's fsid? In this case it would >> be the 509ad44b-... We could print it in that file instead of '1', >> though it could be confusing that it's not the temp_fsid but the >> original one, file name mismatches the contents on first look. > > Instead, can we emit 'fsid' in another kobject altogether? > Furthermore, we also have a 'metadata_uuid' kobject. Here > is how they relate. > > > 1. normally: > > $ cat /sys/fs/btrfs/<meta-fsid>/fsid > <meta-fsid> > $ cat /sys/fs/btrfs/<meta-fsid>/metadata_uuid > <meta-fsid> > > > 2. metadata-uuid flag is set: > > $ cat /sys/fs/btrfs/<sb-fsid>/fsid > <sb-fsid> > $ cat /sys/fs/btrfs/<sb-fsid>/metadata_uuid > <meta-fsid> > > > 3. normal + temp-fsid: > > $ cat /sys/fs/btrfs/<temp-fsid>/fsid > <meta-fsid> > $ cat /sys/fs/btrfs/<temp-fsid>/metadata_uuid > <meta-fsid> > > > 4. metadata-uuid flag is set + temp-fsid: > > $ cat /sys/fs/btrfs/<temp-fsid>/fsid > <sb-fsid> > $ cat /sys/fs/btrfs/<temp-fsid>/metadata_uuid > <meta-fsid> Let's consider this thought: The proposal above implies that /sys/fs/btrfs/<temp-fsid>/temp_fsid will continue to function as described in this patch. Otherwise, determining whether temp_fsid is enabled becomes challenging. As part of the temp-fsid feature, we plan to introduce two additional kobjects. However, if this results in an excessive number of kobjects, then... We have the option to rename /sys/fs/btrfs/<temp-fsid>/temp_fsid to /sys/fs/btrfs/<temp-fsid>/temp-fsid_enabled_super_fsid to display the actual sb::fsid. Thanks, Anand
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index e07be193323a..7f9a4790e013 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -425,6 +425,15 @@ static ssize_t acl_show(struct kobject *kobj, struct kobj_attribute *a, char *bu } BTRFS_ATTR(static_feature, acl, acl_show); +static ssize_t temp_fsid_supported_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + int ret = 0; + + return sysfs_emit(buf, "%d\n", ret); +} +BTRFS_ATTR(static_feature, temp_fsid, temp_fsid_supported_show); + /* * Features which only depend on kernel version. * @@ -438,6 +447,7 @@ static struct attribute *btrfs_supported_static_feature_attrs[] = { BTRFS_ATTR_PTR(static_feature, send_stream_version), BTRFS_ATTR_PTR(static_feature, supported_rescue_options), BTRFS_ATTR_PTR(static_feature, supported_sectorsizes), + BTRFS_ATTR_PTR(static_feature, temp_fsid), NULL }; @@ -1205,6 +1215,15 @@ static ssize_t btrfs_generation_show(struct kobject *kobj, } BTRFS_ATTR(, generation, btrfs_generation_show); +static ssize_t btrfs_temp_fsid_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + struct btrfs_fs_info *fs_info = to_fs_info(kobj); + + return sysfs_emit(buf, "%d\n", fs_info->fs_devices->temp_fsid); +} +BTRFS_ATTR(, temp_fsid, btrfs_temp_fsid_show); + static const char * const btrfs_read_policy_name[] = { "pid" }; static ssize_t btrfs_read_policy_show(struct kobject *kobj, @@ -1307,6 +1326,7 @@ static const struct attribute *btrfs_attrs[] = { BTRFS_ATTR_PTR(, read_policy), BTRFS_ATTR_PTR(, bg_reclaim_threshold), BTRFS_ATTR_PTR(, commit_stats), + BTRFS_ATTR_PTR(, temp_fsid), NULL, };
This adds sysfs objects to indicate temp_fsid feature support and its status. /sys/fs/btrfs/features/temp_fsid /sys/fs/btrfs/<UUID>/temp_fsid For example: Consider two cloned and mounted devices. $ blkid /dev/sdc[1-2] /dev/sdc1: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. /dev/sdc2: UUID="509ad44b-ad2a-4a8a-bc8d-fe69db7220d5" .. One gets actual fsid, and the other gets the temp_fsid when mounted. $ btrfs filesystem show -m Label: none uuid: 509ad44b-ad2a-4a8a-bc8d-fe69db7220d5 Total devices 1 FS bytes used 54.14MiB devid 1 size 300.00MiB used 144.00MiB path /dev/sdc1 Label: none uuid: 33bad74e-c91b-43a5-aef8-b3cab97ae63a Total devices 1 FS bytes used 54.14MiB devid 1 size 300.00MiB used 144.00MiB path /dev/sdc2 Their sysfs as below. $ cat /sys/fs/btrfs/features/temp_fsid 0 $ cat /sys/fs/btrfs/509ad44b-ad2a-4a8a-bc8d-fe69db7220d5/temp_fsid 0 $ cat /sys/fs/btrfs/33bad74e-c91b-43a5-aef8-b3cab97ae63a/temp_fsid 1 Signed-off-by: Anand Jain <anand.jain@oracle.com> --- fs/btrfs/sysfs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)