Bug 1164708

Summary: set-label can only set <=127 bytes for btrfs and <=126 bytes for ntfs filesystem which not meet the help message. Also for ntfs it should give a warning message when the length >128 bytes
Product: Red Hat Enterprise Linux 7 Reporter: Lingfei Kong <lkong>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.1CC: kzak, leiwang, linl, mbooth, ptoscano, wshi, xchen
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.32.0-2.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-03 17:47:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1218766    
Bug Blocks: 1288337, 1301891    
Attachments:
Description Flags
test-label.pl none

Description Lingfei Kong 2014-11-17 08:26:35 UTC
Description of problem:
For btrfs:
I can confirm that the label length for btrfs is less than 256 bytes both in libguestfs and linux system. Check 'help set-label' in guestfish and 'man mkfs.btrfs' in linux system. When i try to set a label who's length is 180 bytes, i can set the label successfully, but when i get the new label via 'vfs-label' i only got 127 bytes.

Also in 'help set-label' i can obtain that i can set 256 bytes for btrfs, obviously this is wrong, for btrfs the max bytes is 255:
><fs> help set-label
[...]
   btrfs
				The label is limited to 256 bytes and some characters are not
				allowed. Setting the label on a btrfs subvolume will set the label
				on its parent filesystem. The filesystem must not be mounted when
				trying to set the label.


For ntfs:
set-label for ntfs can only set <=126 bytes which is less than 128 bytes according to 'help set-label', also it should give a warning message when the length > 128 bytes. Perhaps the limited number is right but the help message is wrong.


Version-Release number of selected component (if applicable):
libguestfs-1.28.1-1.10.el7


How reproducible:
100%


Steps to Reproduce:
1. # str="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d"
   # echo ${#str}
180

2. #guestfish -N fs:btrfs
><fs> set-label  /dev/sda1 2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d
><fs> vfs-label /dev/sda1
2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-

# str2="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-"
# echo ${#str2}
127

3. Check 'help set-label' in guestfish

4. # str="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d"
   # echo ${#str}
180

5. #guestfish -N fs:ntfs
><fs> set-label  /dev/sda1 2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d
><fs> vfs-label /dev/sda1
2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955f2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-

# str2="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955f2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-"
# echo ${#str2}
126

6. Check 'help set-label' in guestfish


Actual results:
At step 2, only get the first 127 bytes of the label name
At step 3, the limited number is 256 which is wrong
At step 5, only get the first 126 bytes of the label name


Expected results:
At step 2, i can get the right label name(180 bytes) when i run 'vfs-label /dev/sda1'
At step 3, the limited number should be 255
At step 5, can get the first 128 bytes of the label name when i run 'vfs-label /dev/sda1'

Additional info:

Comment 1 Richard W.M. Jones 2014-11-17 09:21:32 UTC
Created attachment 958200 [details]
test-label.pl

Attached is a useful script to test the behaviour of labels.

$ ./test-label.pl btrfs 0 256 ascii
0	ok
1	ok
2	ok
3	ok
4	ok
5	ok
[...]
125	ok
126	ok
127	ok
128	truncated to 127
129	truncated to 127
130	truncated to 127
131	truncated to 127
[...]
254	truncated to 127
255	truncated to 127
256	error setting label: set_label: ERROR: Label aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa is too long (max 255) at /tmp/test-label.pl line 36.


or:

$ ./test-label.pl btrfs 0 256 unicode

Comment 2 Richard W.M. Jones 2014-11-17 09:30:02 UTC
So using my script it looks as if the real limits are:

 - ext2/3/4: 16 bytes
 - btrfs: 127 bytes (this contradicts the btrfs documentation)
 - ntfs: behaviour is very strange, especially when using non-ASCII

I'm not sure that libguestfs should be checking limits at all.
It seems to invite trouble.  We should just pass labels through
to the underlying utilities and let them deal with error cases.

Comment 3 Lingfei Kong 2014-11-17 11:21:03 UTC
(In reply to Richard W.M. Jones from comment #2)
> So using my script it looks as if the real limits are:
> 
>  - ext2/3/4: 16 bytes
>  - btrfs: 127 bytes (this contradicts the btrfs documentation)
>  - ntfs: behaviour is very strange, especially when using non-ASCII
> 
> I'm not sure that libguestfs should be checking limits at all.
> It seems to invite trouble.  We should just pass labels through
> to the underlying utilities and let them deal with error cases.

I have encountered many cases that a software auto truncate a long name without give a warning message, anyway extX, btrfs, xfs,ntfs should have the same behavior(give or not give warning messages) when the label length > limited number.

Comment 4 Pino Toscano 2015-01-14 09:34:28 UTC
(In reply to Richard W.M. Jones from comment #2)
> So using my script it looks as if the real limits are:
> 
>  - btrfs: 127 bytes (this contradicts the btrfs documentation)

This does not seem a bug in btrfs, but rather in util-linux. If I change vfs_label to use `btrfs filesystem label` to get the label of a btrfs filesystem, I get the correct result, not truncated.

I'm going to post a patch to use `btrfs` to get the label of btrfs filesystems, if present; this should give the actual value.

I'll deal with util-linux later, as it seems libblkid cannot cope with file system labels longer than 127 characters.

Comment 5 Karel Zak 2015-01-14 10:02:50 UTC
Added to libblkid TODO, will be fixed later this year (I guess it's no urgent issue).

Comment 6 Pino Toscano 2015-01-14 15:25:28 UTC
(In reply to Pino Toscano from comment #4)
> I'm going to post a patch to use `btrfs` to get the label of btrfs
> filesystems, if present; this should give the actual value.

Patch posted:
  https://www.redhat.com/archives/libguestfs/2015-January/msg00037.html

Comment 7 Pino Toscano 2015-01-14 15:34:55 UTC
(In reply to Richard W.M. Jones from comment #2)
> So using my script it looks as if the real limits are:
> 
>  - ntfs: behaviour is very strange, especially when using non-ASCII

This is another issue in util-linux, as it seems (at least with util-linux 2.24.x) it does not decode the label (the volume name, actually) correctly.

If I change vfs_label to use `ntfslabel` for getting the label of ntfs filesystems, then I get the correct result, which is at most 128 unicode characters as stated in the man page. Unfortunately, even ntfslabel (at least as part of ntfsprogs/ntfs-3g 2014.2.15-1.fc20) silently truncates to the maximum, printing a warning and still exiting with 0...

Comment 8 Pino Toscano 2015-01-19 15:51:26 UTC
https://github.com/libguestfs/libguestfs/commit/6db3c100e7c18820ff9ecc22415940eb5fedc64e
this uses btrfs(1) for btrfs partitions

https://github.com/libguestfs/libguestfs/commit/8ad667f1983e98347f4d292c07f971d5362ff052
this uses ntfslabel(1) for ntfs partitions

Comment 12 Hu Zhang 2015-05-06 09:36:00 UTC
Not fixed completely.
Test with libguestfs-1.28.1-1.29.el7.

Step to verify:
1. For btrfs, the 'help set-label' in guestfish says that The label is limited to 256 bytes. Now from the result following, we can only set a label with 255 bytes. So need some modification here.
# ./test-label.pl btrfs 0 256 ascii
0       ok
1       ok
2       ok
...
253     ok
254     ok
255     ok
256     error setting label: set_label: ERROR: Label aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa is too long (max 255) at ./test-label.pl line 36.


2. For ntfs, works well now.
# ./test-label.pl ntfs 0 129 unicode
0       ok
1       ok
2       ok
...
127     ok
128     ok
129     truncated to 384

So, for btrfs, the limited number is 256 which is wrong.

Comment 14 Richard W.M. Jones 2015-07-08 21:15:40 UTC
Move to RHEL 7.3 since we don't have a working upstream fix yet.

Comment 16 Pino Toscano 2015-10-05 09:46:53 UTC
(In reply to Hu Zhang from comment #12)
> 1. For btrfs, the 'help set-label' in guestfish says that The label is
> limited to 256 bytes. Now from the result following, we can only set a label
> with 255 bytes. So need some modification here.

We don't do checks on btrfs labels, as luckly the btrfs tools (e.g. `btrfs filesystem label`) do proper checks on their own, issuing errors (unlike tools for most of the other filesystems for which we can set labels).

This is just a documentation issue for set-label, and I've just pushed
https://github.com/libguestfs/libguestfs/commit/1f47ba92f20b812c8fe2fd6359b648863a8bcac4
which is in libguestfs >= 1.31.11.

Comment 19 Xianghua Chen 2016-06-28 07:43:45 UTC
Verified with the packages:
libguestfs-1.32.5-6.el7.x86_64

Verify steps:
1. # ./test-label.pl ntfs 0 129 unicode
0       ok
1       ok
2       ok
...
127     ok
128     ok
129     truncated to 384

It's ok.

2. # guestfish
><fs> help set-label
   btrfs
        The label is limited to 255 bytes and some characters are not
        allowed. Setting the label on a btrfs subvolume will set the label
        on its parent filesystem. The filesystem must not be mounted when
        trying to set the label.

It has been changed to 255 from 256.

So verified.

Comment 21 errata-xmlrpc 2016-11-03 17:47:18 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2016-2576.html