Directories in /sys/devices/jailhouse/cells/ formerly represented cell names.

This patch changes this structure. From now on, /sys/devices/jailhouse/cells/
will contain cell ids. The name of a specific cell got moved to
/sys/devices/jailhouse/cells/<id>/name.

This makes the sysfs interface easier to be parsed by applications.

Also align documentation, jailhouse-cell-list and
jailhouse-completion.bash to the changes.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 Documentation/sysfs-entries.txt |  4 ++--
 driver/sysfs.c                  | 14 +++++++-------
 tools/jailhouse-cell-list       |  4 ++--
 tools/jailhouse-completion.bash | 14 +++++---------
 4 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/Documentation/sysfs-entries.txt b/Documentation/sysfs-entries.txt
index 2845220..0fc315a 100644
--- a/Documentation/sysfs-entries.txt
+++ b/Documentation/sysfs-entries.txt
@@ -11,8 +11,8 @@ can be used for monitoring the state of the hypervisor and 
its cells.
 |- remap_pool_size              - number of pages in hypervisor remapping pool
 |- remap_pool_used              - used pages of hypervisor remapping pool
 `- cells
-   |- <name of cell>
-   |  |- id                     - unique numerical ID
+   |- <id>                      - unique numerical ID
+   |  |- name                   - cell name
    |  |- state                  - "running", "running/locked", "shut down", or
    |  |                           "failed"
    |  |- cpus_assigned          - bitmask of assigned logical CPUs
diff --git a/driver/sysfs.c b/driver/sysfs.c
index a18c2b9..8c2a11f 100644
--- a/driver/sysfs.c
+++ b/driver/sysfs.c
@@ -139,12 +139,12 @@ static struct attribute_group stats_attr_group = {
        .name = "statistics"
 };
 
-static ssize_t id_show(struct kobject *kobj, struct kobj_attribute *attr,
-                      char *buffer)
+static ssize_t name_show(struct kobject *kobj, struct kobj_attribute *attr,
+                        char *buffer)
 {
        struct cell *cell = container_of(kobj, struct cell, kobj);
 
-       return sprintf(buffer, "%u\n", cell->id);
+       return sprintf(buffer, "%s\n", cell->name);
 }
 
 static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
@@ -212,14 +212,14 @@ static ssize_t cpus_failed_show(struct kobject *kobj,
        return written;
 }
 
-static struct kobj_attribute cell_id_attr = __ATTR_RO(id);
+static struct kobj_attribute cell_name_attr = __ATTR_RO(name);
 static struct kobj_attribute cell_state_attr = __ATTR_RO(state);
 static struct kobj_attribute cell_cpus_assigned_attr =
        __ATTR_RO(cpus_assigned);
 static struct kobj_attribute cell_cpus_failed_attr = __ATTR_RO(cpus_failed);
 
 static struct attribute *cell_attrs[] = {
-       &cell_id_attr.attr,
+       &cell_name_attr.attr,
        &cell_state_attr.attr,
        &cell_cpus_assigned_attr.attr,
        &cell_cpus_failed_attr.attr,
@@ -236,8 +236,8 @@ int jailhouse_sysfs_cell_create(struct cell *cell)
 {
        int err;
 
-       err = kobject_init_and_add(&cell->kobj, &cell_type, cells_dir, "%s",
-                                  cell->name);
+       err = kobject_init_and_add(&cell->kobj, &cell_type, cells_dir, "%d",
+                                  cell->id);
        if (err) {
                jailhouse_cell_kobj_release(&cell->kobj);
                return err;
diff --git a/tools/jailhouse-cell-list b/tools/jailhouse-cell-list
index 3b5bc20..d4123f6 100755
--- a/tools/jailhouse-cell-list
+++ b/tools/jailhouse-cell-list
@@ -54,8 +54,8 @@ if len(sys.argv) > 1:
 cells = []
 for cell_path in glob.glob('/sys/devices/jailhouse/cells/*'):
     cells.append({
-        'name': os.path.basename(cell_path),
-        'id': open(cell_path + "/id").readline().strip(),
+        'id': os.path.basename(cell_path),
+        'name': open(cell_path + "/name").readline().strip(),
         'state': open(cell_path + "/state").readline().strip(),
         'cpus_assigned': read_cpus(cell_path + "/cpus_assigned"),
         'cpus_failed': read_cpus(cell_path + "/cpus_failed")
diff --git a/tools/jailhouse-completion.bash b/tools/jailhouse-completion.bash
index a20ea3c..2e4b379 100644
--- a/tools/jailhouse-completion.bash
+++ b/tools/jailhouse-completion.bash
@@ -66,12 +66,9 @@ function _jailhouse_get_id() {
 
                # get possible ids and names
                if [ -d /sys/devices/jailhouse/cells ]; then
-                       for i in /sys/devices/jailhouse/cells/*/id; do
-                               ids="${ids} $(cat "${i}" | tr '\n' ' ')"
-                       done
-                       for n in /sys/devices/jailhouse/cells/*; do
-                               _quote_readline_by_ref "${n##*/}" quoted
-                               names="${names} ${quoted}"
+                       for i in /sys/devices/jailhouse/cells/*; do
+                               ids="${ids} ${i##*/}"
+                               names="${names} $(<${i}/name)"
                        done
                fi
 
@@ -85,9 +82,8 @@ function _jailhouse_get_id() {
 
                # get possible names
                if [ -d /sys/devices/jailhouse/cells ]; then
-                       for n in /sys/devices/jailhouse/cells/*; do
-                               _quote_readline_by_ref "${n##*/}" quoted
-                               names="${names} ${quoted}"
+                       for n in /sys/devices/jailhouse/cells/*/name; do
+                               names="${names} $(<${n})"
                        done
                fi
 
-- 
2.9.3

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to