summaryrefslogtreecommitdiff
path: root/sutils
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-03-16 01:48:40 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2016-03-16 01:48:40 +0100
commit4f51b0e104481fb6d337140eeaa51af8c674d236 (patch)
tree452aacaf7f586e2ccd22bda15a92419d9616065b /sutils
parent0bc52ecb504401e089e1aa335c56e0c5db6d8e32 (diff)
Add getting swap information from swapon and procfs
* hurd/default_pager.defs (default_pager_storage_info): New RPC. * hurd/default_pager_reply.defs: Skip default_pager_storage_info RPC. * hurd/default_pager_types.h: Include <mach/machine/vm_types.h>. (vm_size_array_t): New type. * mach-defpager/priv.h (part): Add `name' field. * mach-defpager/default_pager.c (new_partition): Allocate and fill `part->name' field. Free it on error. (destroy_paging_partition): Free `part->name' field. (S_default_pager_storage_info): New function. * procfs/Makefile (SRCS): Add default_pagerUser.c. * procfs/rootdir.c: Include "default_pager_U.h". (rootdir_gc_swaps): New function. (rootdir_entries): Add "swaps" entry. * sutils/swapon.c: Include <argz.h> (show): New variable. (options): Add --show/-S option. (def_pager, dev_master): New variables (swaponoff): Move getting `def_pager' to... (get_def_pager): ... new function. (main): Support 'S' option. * trans/proxy-defpager.c (S_default_pager_storage_info): New function.
Diffstat (limited to 'sutils')
-rw-r--r--sutils/swapon.c107
1 files changed, 76 insertions, 31 deletions
diff --git a/sutils/swapon.c b/sutils/swapon.c
index 2403f1c2..ae830baa 100644
--- a/sutils/swapon.c
+++ b/sutils/swapon.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <stdint.h>
#include <argp.h>
+#include <argz.h>
#include <error.h>
#include <assert.h>
#include <sys/mman.h>
@@ -42,7 +43,7 @@ const char *argp_program_version = STANDARD_HURD_VERSION (swapoff);
const char *argp_program_version = STANDARD_HURD_VERSION (swapon);
#endif
-static int ignore_signature, require_signature, quiet, ifexists;
+static int ignore_signature, require_signature, show, quiet, ifexists;
static struct argp_option options[] =
{
@@ -54,6 +55,8 @@ static struct argp_option options[] =
"Do not check for a Linux swap signature page"},
{"require-signature", 's', 0, 0,
"Require a Linux swap signature page"},
+ {"show", 'S', 0, 0,
+ "Show devices currently in use"},
{"silent", 'q', 0, 0, "Print only diagnostic messages"},
{"quiet", 'q', 0, OPTION_ALIAS | OPTION_HIDDEN },
{"verbose", 'v', 0, 0, "Be verbose"},
@@ -81,6 +84,39 @@ static char *doc =
verbose ("%s: Linux 2.2 swap signature v1, %zuk swap-space" fmt, \
name, freepages * (LINUX_PAGE_SIZE / 1024) ,##arg)
+
+static mach_port_t def_pager = MACH_PORT_NULL;
+static mach_port_t dev_master = MACH_PORT_NULL;
+
+static void get_def_pager(void)
+{
+ int err;
+ mach_port_t host;
+
+ if (def_pager != MACH_PORT_NULL)
+ return;
+
+ err = get_privileged_ports (&host, &dev_master);
+ if (err == EPERM)
+ {
+ /* We are not root, so try opening the /servers node. */
+ def_pager = file_name_lookup (_SERVERS_DEFPAGER, O_WRITE, 0);
+ if (def_pager == MACH_PORT_NULL)
+ error (11, errno, _SERVERS_DEFPAGER);
+ }
+ else
+ {
+ if (err)
+ error (12, err, "Cannot get privileged ports");
+
+ err = vm_set_default_memory_manager (host, &def_pager);
+ mach_port_deallocate (mach_task_self (), host);
+ if (err)
+ error (13, err, "Cannot get default pager port");
+ if (def_pager == MACH_PORT_NULL)
+ error (14, 0, "No default pager (memory manager) is running!");
+ }
+}
/* Examine the store in *STOREP to see if it has a Linux-compatible
swap signature page as created by the Linux `mkswap' utility. If
@@ -326,8 +362,6 @@ swaponoff (const char *file, int add, int skipnotexisting)
{
error_t err;
struct store *store;
- static mach_port_t def_pager = MACH_PORT_NULL;
- static mach_port_t dev_master = MACH_PORT_NULL;
static int old_protocol;
int quiet_now = 0;
@@ -384,34 +418,7 @@ swaponoff (const char *file, int add, int skipnotexisting)
return EINVAL;
}
- if (def_pager == MACH_PORT_NULL)
- {
- mach_port_t host;
-
- err = get_privileged_ports (&host, &dev_master);
- if (err == EPERM)
- {
- /* We are not root, so try opening the /servers node. */
- def_pager = file_name_lookup (_SERVERS_DEFPAGER, O_WRITE, 0);
- if (def_pager == MACH_PORT_NULL)
- {
- error (11, errno, _SERVERS_DEFPAGER);
- return 0;
- }
- }
- else
- {
- if (err)
- error (12, err, "Cannot get privileged ports");
-
- err = vm_set_default_memory_manager (host, &def_pager);
- mach_port_deallocate (mach_task_self (), host);
- if (err)
- error (13, err, "Cannot get default pager port");
- if (def_pager == MACH_PORT_NULL)
- error (14, 0, "No default pager (memory manager) is running!");
- }
- }
+ get_def_pager();
if (old_protocol)
{
@@ -487,6 +494,10 @@ main (int argc, char *argv[])
ignore_signature = 0;
break;
+ case 'S':
+ show = 1;
+ break;
+
case 'q':
quiet = 1;
break;
@@ -547,5 +558,39 @@ main (int argc, char *argv[])
}
}
+ if (show)
+ {
+ vm_size_t *free = NULL;
+ size_t nfree = 0;
+ vm_size_t *size = NULL;
+ size_t nsize = 0;
+ char *names = NULL, *name;
+ size_t names_len = 0;
+ size_t i;
+ int err;
+
+ get_def_pager();
+
+ err = default_pager_storage_info (def_pager, &free, &nfree, &size, &nsize,
+ &names, &names_len);
+ if (err)
+ error (3, 0, "Can not get default pager storage information");
+
+ printf("Filename\tType\t\tSize\tUsed\tPriority\n");
+ name = names;
+ for (i = 0; i < nfree; i++)
+ {
+ printf ("/dev/%s\tpartition\t%zuM\t%zuM\t-1\n",
+ name, size[i] >> 20, (size[i] - free[i]) >> 20);
+ name = argz_next (names, names_len, name);
+ }
+
+ vm_deallocate (mach_task_self(), (vm_offset_t) free,
+ nfree * sizeof(*free));
+ vm_deallocate (mach_task_self(), (vm_offset_t) size,
+ nsize * sizeof(*size));
+ vm_deallocate (mach_task_self(), (vm_offset_t) names, names_len);
+ }
+
return 0;
}