---
daemon/daemon.h | 1 +
daemon/labels.c | 3 +++
daemon/swap.c | 21 +++++++++++++++++++++
generator/actions.ml | 4 ++++
4 files changed, 29 insertions(+)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 79a5288..2379e31 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -254,6 +254,7 @@ extern int64_t ntfs_minimum_size (const char *device);
/*-- in swap.c --*/
extern int swap_set_uuid (const char *device, const char *uuid);
+extern int swap_set_label (const char *device, const char *label);
/* ordinary daemon functions use these to indicate errors
* NB: you don't need to prefix the string with the current command,
diff --git a/daemon/labels.c b/daemon/labels.c
index 20f27cb..aaa3eaf 100644
--- a/daemon/labels.c
+++ b/daemon/labels.c
@@ -85,6 +85,9 @@ do_set_label (const mountable_t *mountable, const char *label)
else if (STREQ (vfs_type, "xfs"))
r = xfslabel (mountable->device, label);
+ else if (STREQ (vfs_type, "swap"))
+ r = swap_set_label (mountable->device, label);
+
else
NOT_SUPPORTED (-1, "don't know how to set the label for '%s'
filesystems",
vfs_type);
diff --git a/daemon/swap.c b/daemon/swap.c
index 9d7839e..028bc1e 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -239,3 +239,24 @@ swap_set_uuid (const char *device, const char *uuid)
return 0;
}
+
+int
+swap_set_label (const char *device, const char *label)
+{
+ int r;
+ CLEANUP_FREE char *err = NULL;
+
+ if (strlen (label) > SWAP_LABEL_MAX) {
+ reply_with_error ("%s: Linux swap labels are limited to %d bytes",
+ label, SWAP_LABEL_MAX);
+ return -1;
+ }
+
+ r = command (NULL, &err, str_swaplabel, "-L", label, device, NULL);
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 43de38b..5e0356f 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -10304,6 +10304,10 @@ when trying to set the label.
The label is limited to 11 bytes.
+=item swap
+
+The label is limited to 16 bytes.
+
=back
If there is no support for changing the label
--
2.7.4
_______________________________________________
Libguestfs mailing list
Libguestfs(a)redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs
Obvious improvement, ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat