Skip to content

Commit

Permalink
daemon: use btrfs(1) to get btrfs labels
Browse files Browse the repository at this point in the history
blkid(1) (or actually, libblkid) seems to handle filesystem labels up
to 127 characters. Considering that btrfs labels can be up to 255
characters, this means long labels are not read correctly (i.e. get
truncated) by blkid.

Get the filesystem type, and if btrfs is available invoke
`btrfs filesystem` to get the label of btrfs filesystems.

Related to RHBZ#1164708.
  • Loading branch information
ptoscano committed Jan 19, 2015
1 parent d7abf5c commit 6db3c10
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions daemon/blkid.c
Expand Up @@ -26,6 +26,7 @@

#include "daemon.h"
#include "actions.h"
#include "optgroups.h"

GUESTFSD_EXT_CMD(str_blkid, blkid);

Expand Down Expand Up @@ -76,6 +77,13 @@ do_vfs_type (const mountable_t *mountable)
char *
do_vfs_label (const mountable_t *mountable)
{
CLEANUP_FREE char *type = do_vfs_type (mountable);

if (type) {
if (STREQ (type, "btrfs") && optgroup_btrfs_available ())
return btrfs_get_label (mountable->device);
}

return get_blkid_tag (mountable->device, "LABEL");
}

Expand Down
24 changes: 24 additions & 0 deletions daemon/btrfs.c
Expand Up @@ -44,6 +44,30 @@ optgroup_btrfs_available (void)
return prog_exists (str_btrfs) && filesystem_available ("btrfs") > 0;
}

char *
btrfs_get_label (const char *device)
{
int r;
CLEANUP_FREE char *err = NULL;
char *out = NULL;
size_t len;

r = command (&out, &err, str_btrfs, "filesystem", "label",
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
return NULL;
}

/* Trim trailing \n if present. */
len = strlen (out);
if (len > 0 && out[len-1] == '\n')
out[len-1] = '\0';

return out;
}

/* Takes optional arguments, consult optargs_bitmask. */
int
do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
Expand Down
3 changes: 3 additions & 0 deletions daemon/daemon.h
Expand Up @@ -262,6 +262,9 @@ extern char *debug_bmap (const char *subcmd, size_t argc, char *const *const arg
extern char *debug_bmap_file (const char *subcmd, size_t argc, char *const *const argv);
extern char *debug_bmap_device (const char *subcmd, size_t argc, char *const *const argv);

/*-- in btrfs.c --*/
extern char *btrfs_get_label (const char *device);

/* ordinary daemon functions use these to indicate errors
* NB: you don't need to prefix the string with the current command,
* it is added automatically by the client-side RPC stubs.
Expand Down

0 comments on commit 6db3c10

Please sign in to comment.