diff mbox

[1/2] btrfs-progs: prop: check FS_NOCOMP_FL flag in property get

Message ID 6dabbe1b-87a2-77cd-4fca-9835a1573961@jp.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Misono Tomohiro Dec. 12, 2017, 7:07 a.m. UTC
If "property set ... compression no" is called, it sets FS_NOCOMP_FL flag
(which is equivalent to BTRFS_INODE_NO_COMPRESS in btrfs). This means
compression will not be done and is different from default status.

However, current "property get" won't check the status of FS_NOCOMP_FL and
the output (no output message) cannot be distinguished from the default
status when the flag is set. 

Fix this to call FS_IOC_GETFLAGS to check FS_NOCOMP_FL flag and print
"compression=no" if the flag is set.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
---
 props.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/props.c b/props.c
index cddbd927..3af349af 100644
--- a/props.c
+++ b/props.c
@@ -14,6 +14,7 @@ 
  * Boston, MA 021110-1307, USA.
  */
 
+#include <linux/fs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
@@ -151,11 +152,19 @@  static int prop_compression(enum prop_object_type type,
 	}
 	if (sret < 0) {
 		ret = -errno;
-		if (ret != -ENOATTR)
+		if (ret != -ENOATTR) {
 			error("failed to %s compression for %s: %s",
 			      value ? "set" : "get", object, strerror(-ret));
-		else
-			ret = 0;
+		} else {
+			unsigned int flags = 0;
+
+			ret = ioctl(fd, FS_IOC_GETFLAGS, &flags);
+			if (ret)
+				error("failed to get FS_FLAGS for %s: %s",
+						object, strerror(ret));
+			else if (flags & FS_NOCOMP_FL)
+				fprintf(stdout, "compression=no\n");
+		}
 		goto out;
 	}
 	if (!value) {