|
|
ffd6ed |
From d16202fa66f981949fc49573030721cda35705dc Mon Sep 17 00:00:00 2001
|
|
|
ffd6ed |
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
ffd6ed |
Date: Wed, 14 Jan 2015 18:55:13 +0100
|
|
|
ffd6ed |
Subject: [PATCH] daemon: use btrfs(1) to get btrfs labels
|
|
|
ffd6ed |
|
|
|
ffd6ed |
blkid(1) (or actually, libblkid) seems to handle filesystem labels up
|
|
|
ffd6ed |
to 127 characters. Considering that btrfs labels can be up to 255
|
|
|
ffd6ed |
characters, this means long labels are not read correctly (i.e. get
|
|
|
ffd6ed |
truncated) by blkid.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
Get the filesystem type, and if btrfs is available invoke
|
|
|
ffd6ed |
`btrfs filesystem` to get the label of btrfs filesystems.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
Related to RHBZ#1164708.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
(cherry picked from commit 6db3c100e7c18820ff9ecc22415940eb5fedc64e)
|
|
|
ffd6ed |
---
|
|
|
ffd6ed |
daemon/blkid.c | 8 ++++++++
|
|
|
ffd6ed |
daemon/btrfs.c | 24 ++++++++++++++++++++++++
|
|
|
ffd6ed |
daemon/daemon.h | 3 +++
|
|
|
ffd6ed |
3 files changed, 35 insertions(+)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/daemon/blkid.c b/daemon/blkid.c
|
|
|
ffd6ed |
index b98c155..e8e7b58 100644
|
|
|
ffd6ed |
--- a/daemon/blkid.c
|
|
|
ffd6ed |
+++ b/daemon/blkid.c
|
|
|
ffd6ed |
@@ -26,6 +26,7 @@
|
|
|
ffd6ed |
|
|
|
ffd6ed |
#include "daemon.h"
|
|
|
ffd6ed |
#include "actions.h"
|
|
|
ffd6ed |
+#include "optgroups.h"
|
|
|
ffd6ed |
|
|
|
ffd6ed |
GUESTFSD_EXT_CMD(str_blkid, blkid);
|
|
|
ffd6ed |
|
|
|
ffd6ed |
@@ -76,6 +77,13 @@ do_vfs_type (const mountable_t *mountable)
|
|
|
ffd6ed |
char *
|
|
|
ffd6ed |
do_vfs_label (const mountable_t *mountable)
|
|
|
ffd6ed |
{
|
|
|
ffd6ed |
+ CLEANUP_FREE char *type = do_vfs_type (mountable);
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
+ if (type) {
|
|
|
ffd6ed |
+ if (STREQ (type, "btrfs") && optgroup_btrfs_available ())
|
|
|
ffd6ed |
+ return btrfs_get_label (mountable->device);
|
|
|
ffd6ed |
+ }
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
return get_blkid_tag (mountable->device, "LABEL");
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
|
|
|
ffd6ed |
index 7a4d43d..86bad36 100644
|
|
|
ffd6ed |
--- a/daemon/btrfs.c
|
|
|
ffd6ed |
+++ b/daemon/btrfs.c
|
|
|
ffd6ed |
@@ -42,6 +42,30 @@ optgroup_btrfs_available (void)
|
|
|
ffd6ed |
return prog_exists (str_btrfs) && filesystem_available ("btrfs") > 0;
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
|
|
|
ffd6ed |
+char *
|
|
|
ffd6ed |
+btrfs_get_label (const char *device)
|
|
|
ffd6ed |
+{
|
|
|
ffd6ed |
+ int r;
|
|
|
ffd6ed |
+ CLEANUP_FREE char *err = NULL;
|
|
|
ffd6ed |
+ char *out = NULL;
|
|
|
ffd6ed |
+ size_t len;
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
+ r = command (&out, &err, str_btrfs, "filesystem", "label",
|
|
|
ffd6ed |
+ device, NULL);
|
|
|
ffd6ed |
+ if (r == -1) {
|
|
|
ffd6ed |
+ reply_with_error ("%s", err);
|
|
|
ffd6ed |
+ free (out);
|
|
|
ffd6ed |
+ return NULL;
|
|
|
ffd6ed |
+ }
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
+ /* Trim trailing \n if present. */
|
|
|
ffd6ed |
+ len = strlen (out);
|
|
|
ffd6ed |
+ if (len > 0 && out[len-1] == '\n')
|
|
|
ffd6ed |
+ out[len-1] = '\0';
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
+ return out;
|
|
|
ffd6ed |
+}
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
/* Takes optional arguments, consult optargs_bitmask. */
|
|
|
ffd6ed |
int
|
|
|
ffd6ed |
do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
|
|
|
ffd6ed |
diff --git a/daemon/daemon.h b/daemon/daemon.h
|
|
|
ffd6ed |
index f442efd..24ee46a 100644
|
|
|
ffd6ed |
--- a/daemon/daemon.h
|
|
|
ffd6ed |
+++ b/daemon/daemon.h
|
|
|
ffd6ed |
@@ -257,6 +257,9 @@ extern int copy_xattrs (const char *src, const char *dest);
|
|
|
ffd6ed |
/* Documented in xfs_admin(8). */
|
|
|
ffd6ed |
#define XFS_LABEL_MAX 12
|
|
|
ffd6ed |
|
|
|
ffd6ed |
+/*-- in btrfs.c --*/
|
|
|
ffd6ed |
+extern char *btrfs_get_label (const char *device);
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
/* ordinary daemon functions use these to indicate errors
|
|
|
ffd6ed |
* NB: you don't need to prefix the string with the current command,
|
|
|
ffd6ed |
* it is added automatically by the client-side RPC stubs.
|
|
|
ffd6ed |
--
|
|
|
ffd6ed |
1.8.3.1
|
|
|
ffd6ed |
|