From 4f51b0e104481fb6d337140eeaa51af8c674d236 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 16 Mar 2016 01:48:40 +0100 Subject: 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 . (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 (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. --- procfs/Makefile | 2 +- procfs/rootdir.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) (limited to 'procfs') diff --git a/procfs/Makefile b/procfs/Makefile index 12fc9eee..13ee026c 100644 --- a/procfs/Makefile +++ b/procfs/Makefile @@ -21,7 +21,7 @@ makemode := server target = procfs -SRCS = procfs.c netfs.c procfs_dir.c process.c proclist.c rootdir.c dircat.c main.c mach_debugUser.c +SRCS = procfs.c netfs.c procfs_dir.c process.c proclist.c rootdir.c dircat.c main.c mach_debugUser.c default_pagerUser.c LCLHDRS = dircat.h main.h process.h procfs.h procfs_dir.h proclist.h rootdir.h OBJS = $(SRCS:.c=.o) diff --git a/procfs/rootdir.c b/procfs/rootdir.c index 93fef8d9..dd693c89 100644 --- a/procfs/rootdir.c +++ b/procfs/rootdir.c @@ -21,6 +21,7 @@ #include #include #include +#include "default_pager_U.h" #include #include #include @@ -521,6 +522,56 @@ rootdir_gc_filesystems (void *hook, char **contents, ssize_t *contents_len) fclose (m); return err; } + +static error_t +rootdir_gc_swaps (void *hook, char **contents, ssize_t *contents_len) +{ + mach_port_t defpager; + error_t err = 0; + FILE *m; + 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; + + m = open_memstream (contents, (size_t *) contents_len); + if (m == NULL) + return errno; + + defpager = file_name_lookup (_SERVERS_DEFPAGER, O_READ, 0); + if (defpager == MACH_PORT_NULL) + { + err = errno; + goto out_fclose; + } + + err = default_pager_storage_info (defpager, &free, &nfree, &size, &nsize, + &names, &names_len); + if (err) + goto out; + + fprintf(m, "Filename\tType\t\tSize\tUsed\tPriority\n"); + name = names; + for (i = 0; i < nfree; i++) + { + fprintf (m, "/dev/%s\tpartition\t%zu\t%zu\t-1\n", + name, size[i] >> 10, (size[i] - free[i]) >> 10); + 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); + +out: + mach_port_deallocate (mach_task_self (), defpager); +out_fclose: + fclose (m); + return err; +} /* Glue logic and entries table */ @@ -703,6 +754,13 @@ static const struct procfs_dir_entry rootdir_entries[] = { .cleanup_contents = procfs_cleanup_contents_with_free, }, }, + { + .name = "swaps", + .hook = & (struct procfs_node_ops) { + .get_contents = rootdir_gc_swaps, + .cleanup_contents = procfs_cleanup_contents_with_free, + }, + }, #ifdef PROFILE /* In order to get a usable gmon.out file, we must apparently use exit(). */ { -- cgit v1.2.3