Re: [PATCH 7/7] libtrivfs: lock-less reference counting for trivfs_peropen objects

2014-05-24 Thread Samuel Thibault
Justus Winter, le Fri 23 May 2014 09:48:35 +0200, a écrit :
> It is an optimization.  This way we can use just 1 atomic operation
> when trivfs_peropen_destroy_hook is not used, and 3 when it is.  If we
> do it like you described, we need two in any case.

Then you could rather use something like:

if (trivfs_peropen_destroy_hook)
{
  do it in two operations
}
else
{
  do it in one operation
}

It doesn't duplicate too much code.

Samuel



Re: [PATCH] Implement /proc/slabinfo

2014-05-24 Thread Samuel Thibault
Justus Winter, le Fri 23 May 2014 08:54:25 +0200, a écrit :
> +  for (i = 0; i < cache_info_count + 1; i++)
> +{
> +  size_t l = strlen (infos[i]);
> +  memcpy (p, infos[i], l);

The length could be stored too, to avoid having to run strlen again.

Samuel



Re: [PATCH] Implement /proc/slabinfo

2014-05-24 Thread Pino Toscano

Il 23.05.2014 08:54 Justus Winter ha scritto:

Add a node 'slabinfo' to the root directory that contains information
about the slab allocator used in GNU Mach.

The formatting code has been taken from Richard Braun's standalone
client available here:

git://darnassus.sceen.net/rbraun/slabinfo.git
[...]
+ infos = malloc ((cache_info_count + 1) * sizeof *infos);
+ if (infos == NULL)
+ return ENOMEM;


What about using FILE + open_memstream to ease the output?

--
Pino Toscano


Scopri istella, il nuovo motore per il web italiano.
Istella garantisce risultati di qualità e la possibilità di 
condividere, in modo semplice e veloce, documenti, immagini, audio e 
video.

Usa istella, vai su http://www.istella.it?wtk=amc138614816829636





[PATCH] utils/mount: add mount options to create firmlinks.

2014-05-24 Thread Gabriele Giacone
* utils/mount.c (parse_opt): Add -B/--bind/--firmlink/-o bind mount
  options.  (do_mount): Do not pass bind mount option to settrans, set
  firmlink fstype.  (main): Likewise.
---
 utils/mount.c | 38 +++---
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/utils/mount.c b/utils/mount.c
index df77c66..e6893cb 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -64,6 +64,8 @@ static const struct argp_option argp_opts[] =
   {"no-mtab", 'n', 0, 0, "Do not update /etc/mtab"},
   {"test-opts", 'O', "OPTIONS", 0,
"Only mount fstab entries matching the given set of options"},
+  {"bind", 'B', 0, 0, "Bind mount, firmlink"},
+  {"firmlink", 0, 0, OPTION_ALIAS},
   {"fake", 'f', 0, 0, "Do not actually mount, just pretend"},
   {0, 0}
 };
@@ -87,6 +89,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 case 'r': ARGZ (add (&options, &options_len, "ro"));
 case 'w': ARGZ (add (&options, &options_len, "rw"));
 case 'u': ARGZ (add (&options, &options_len, "update"));
+case 'B': ARGZ (add (&options, &options_len, "bind"));
 case 'o': ARGZ (add_sep (&options, &options_len, arg, ','));
 case 'v': ++verbose; break;
 #undef ARGZ
@@ -250,12 +253,20 @@ do_mount (struct fs *fs, int remount)
   /* Append the fstab options to any specified on the command line.  */
   ARGZ (create_sep (fs->mntent.mnt_opts, ',', &mntopts, &mntopts_len));
 
-  /* Remove the `noauto' option, since it's for us not the filesystem.  */
+  /* Remove the `noauto' and `bind' options, since they're for us not the
+ filesystem.  */
   for (o = mntopts; o; o = argz_next (mntopts, mntopts_len, o))
-   if (!strcmp (o, MNTOPT_NOAUTO))
- break;
-  if (o)
-   argz_delete (&mntopts, &mntopts_len, o);
+{
+  if (strcmp (o, MNTOPT_NOAUTO) == 0)
+argz_delete (&mntopts, &mntopts_len, o);
+  if (strcmp (o, "bind") == 0)
+{
+  fs->mntent.mnt_type = strdup ("firmlink");
+  if (! fs->mntent.mnt_type)
+error (3, ENOMEM, "failed to allocate memory");
+  argz_delete (&mntopts, &mntopts_len, o);
+}
+}
 
   ARGZ (append (&mntopts, &mntopts_len, options, options_len));
 }
@@ -273,7 +284,7 @@ do_mount (struct fs *fs, int remount)
   {
ARGZ (add (&fsopts, &fsopts_len, o));
   }
-else if (strcmp (o, "defaults") != 0)
+else if ((strcmp (o, "defaults") != 0) && (strlen (o) != 0))
   {
/* Prepend `--' to the option to make a long option switch,
   e.g. `--ro' or `--rsize=1024'.  */
@@ -572,7 +583,7 @@ do_query (struct fs *fs)
 int
 main (int argc, char **argv)
 {
-  unsigned int remount;
+  unsigned int remount, firmlink;
   struct fstab *fstab;
   struct fs *fs;
   error_t err;
@@ -598,6 +609,15 @@ main (int argc, char **argv)
   if (err)
 error (3, ENOMEM, "collecting mount options");
 
+  /* Do not pass `bind' option to firmlink translator */
+  char *opt = NULL;
+  while ((opt = argz_next (options, options_len, opt)))
+if (strcmp (opt, "bind") == 0)
+  {
+firmlink = 1;
+argz_delete(&options, &options_len, opt);
+  }
+
   if (device)  /* two-argument form */
 {
   struct mntent m =
@@ -608,6 +628,8 @@ main (int argc, char **argv)
mnt_opts: 0,
mnt_freq: 0, mnt_passno: 0
   };
+  if (firmlink)
+m.mnt_type = strdup ("firmlink");
 
   err = fstab_add_mntent (fstab, &m, &fs);
   if (err)
@@ -625,6 +647,8 @@ main (int argc, char **argv)
mnt_opts: 0,
mnt_freq: 0, mnt_passno: 0
   };
+  if (firmlink)
+m.mnt_type = strdup ("firmlink");
 
   err = fstab_add_mntent (fstab, &m, &fs);
   if (err)
-- 
2.0.0.rc2




Re: [PATCH] Implement /proc/slabinfo

2014-05-24 Thread Justus Winter
Quoting Pino Toscano (2014-05-24 11:03:48)
> Il 23.05.2014 08:54 Justus Winter ha scritto:
> > Add a node 'slabinfo' to the root directory that contains information
> > about the slab allocator used in GNU Mach.
> >
> > The formatting code has been taken from Richard Braun's standalone
> > client available here:
> >
> > git://darnassus.sceen.net/rbraun/slabinfo.git
> > [...]
> > + infos = malloc ((cache_info_count + 1) * sizeof *infos);
> > + if (infos == NULL)
> > + return ENOMEM;
> 
> What about using FILE + open_memstream to ease the output?

Much nicer, indeed! Thanks for introducing me to this gem :)

(Also, I forgot to vm_deallocate cache_info.)

Justus



[PATCH] Implement /proc/slabinfo

2014-05-24 Thread Justus Winter
Add a node 'slabinfo' to the root directory that contains information
about the slab allocator used in GNU Mach.

The formatting code has been taken from Richard Braun's standalone
client available here:

git://darnassus.sceen.net/rbraun/slabinfo.git

* rootdir.c (rootdir_gc_slabinfo): New function.
(rootdir_entries): Add node 'slabinfo'.
* Makefile (OBJS): Add mach_debugUser.o.
(rootdir.o): Add an explicit dependency on mach_debug_U.h.
Furthermore, add rules to create both functions.
---
 Makefile  | 22 ++-
 rootdir.c | 73 +++
 2 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 5c51c1d..2820596 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 TARGET = procfs
 OBJS = procfs.o netfs.o procfs_dir.o \
-   process.o proclist.o rootdir.o dircat.o main.o
+   process.o proclist.o rootdir.o dircat.o main.o mach_debugUser.o
 LIBS = -lnetfs -lps -lfshelp -lpthread
 
 CC = gcc
@@ -19,8 +19,28 @@ CPPFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
 
 all: $(TARGET)
 
+rootdir.o: rootdir.c mach_debug_U.h
+
 $(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 clean:
$(RM) $(TARGET) $(OBJS)
+
+# This is the gist of the MIG user stub handling from Hurd's build
+# system:
+
+# Where to find .defs files.
+vpath %.defs /usr/include/mach_debug
+
+MIG = mig
+MIGCOM = $(MIG) -cc cat - /dev/null
+MIGCOMFLAGS := -subrprefix __
+
+%.udefsi: %.defs
+   $(CPP) -x c $(CPPFLAGS) $(MIGUFLAGS) $($*-MIGUFLAGS) \
+ $< -o $*.udefsi
+
+%_U.h %User.c: %.udefsi
+   $(MIGCOM) $(MIGCOMFLAGS) $(MIGCOMUFLAGS) $($*-MIGCOMUFLAGS) < $< \
+ -user $*User.c -server /dev/null -header $*_U.h
diff --git a/rootdir.c b/rootdir.c
index 94b0ddb..076885c 100644
--- a/rootdir.c
+++ b/rootdir.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -35,6 +36,8 @@
 #include "procfs_dir.h"
 #include "main.h"
 
+#include "mach_debug_U.h"
+
 /* This implements a directory node with the static files in /proc.
NB: the libps functions for host information return static storage;
using them would require locking and as a consequence it would be
@@ -470,6 +473,69 @@ rootdir_mounts_exists (void *dir_hook, const void 
*entry_hook)
 translator_exists = access (MTAB_TRANSLATOR, F_OK|X_OK) == 0;
   return translator_exists;
 }
+
+static error_t
+rootdir_gc_slabinfo (void *hook, char **contents, ssize_t *contents_len)
+{
+  error_t err;
+  FILE *m;
+  const char header[] =
+"cache  obj slab  bufs   objs   bufs"
+"total reclaimable\n"
+"name  flags   size size /slab  usage  count"
+"   memory  memory\n";
+  cache_info_array_t cache_info;
+  size_t mem_usage, mem_reclaimable, mem_total, mem_total_reclaimable;
+  mach_msg_type_number_t cache_info_count;
+  int i;
+
+  cache_info = NULL;
+  cache_info_count = 0;
+
+  err = host_slab_info (mach_host_self(), &cache_info, &cache_info_count);
+  if (err)
+return err;
+
+  m = open_memstream (contents, contents_len);
+  if (m == NULL)
+{
+  err = ENOMEM;
+  goto out;
+}
+
+  fprintf (m, "%s", header);
+
+  mem_total = 0;
+  mem_total_reclaimable = 0;
+
+  for (i = 0; i < cache_info_count; i++)
+{
+  mem_usage = (cache_info[i].nr_slabs * cache_info[i].slab_size)
+   >> 10;
+  mem_total += mem_usage;
+  mem_reclaimable = (cache_info[i].flags & CACHE_FLAGS_NO_RECLAIM)
+   ? 0 : (cache_info[i].nr_free_slabs
+  * cache_info[i].slab_size) >> 10;
+  mem_total_reclaimable += mem_reclaimable;
+  fprintf (m,
+   "%-21s %04x %7zu %3zuk  %4lu %6lu %6lu %7zuk %10zuk\n",
+   cache_info[i].name, cache_info[i].flags,
+   cache_info[i].obj_size, cache_info[i].slab_size >> 10,
+   cache_info[i].bufs_per_slab, cache_info[i].nr_objs,
+   cache_info[i].nr_bufs, mem_usage, mem_reclaimable);
+}
+
+  fprintf (m, "total: %zuk, reclaimable: %zuk\n",
+   mem_total, mem_total_reclaimable);
+
+  fclose (m);
+  *contents_len += 1;  /* For the terminating 0.  */
+
+ out:
+  vm_deallocate (mach_task_self (),
+ cache_info, cache_info_count * sizeof *cache_info);
+  return err;
+}
 
 /* Glue logic and entries table */
 
@@ -563,6 +629,13 @@ static const struct procfs_dir_entry rootdir_entries[] = {
   .exists = rootdir_mounts_exists,
 }
   },
+  {
+.name = "slabinfo",
+.hook = & (struct procfs_node_ops) {
+  .get_contents = rootdir_gc_slabinfo,
+  .cleanup_contents = procfs_cleanup_contents_with_free,
+},
+  },
 #ifdef PROFILE
   /* In order to get a usable gmon.out file, we must apparently use exit(). */
   {
-- 
2.0.0.rc2




Re: [PATCH] Implement /proc/slabinfo

2014-05-24 Thread Samuel Thibault
Justus Winter, le Sat 24 May 2014 12:45:40 +0200, a écrit :
> > What about using FILE + open_memstream to ease the output?
> 
> Much nicer, indeed! Thanks for introducing me to this gem :)

The great thing about working in userland ;)

Samuel



[PATCH] build: Remove checks for 'getgrouplist' and 'uselocale'

2014-05-24 Thread Ludovic Courtès
This patch removes configure checks that have long been unneeded.

OK to apply?

Ludo’.

>From a8b1c2e3c5cd89f26b6856c63fd3ba625a36ad54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= 
Date: Sun, 25 May 2014 01:06:50 +0200
Subject: [PATCH] build: Remove checks for 'getgrouplist' and 'uselocale'.

GNU libc has had them for a long time.

* configure.ac: Remove checks for 'getgrouplist' and 'uselocale'.
* libshouldbeinlibc/idvec-impgids.c (_merge_implied_gids): Remove #ifdef
  HAVE_GETGROUPLIST and remove #else arm.
* libthreads/cthreads.c: Remove #ifdef HAVE_USELOCALE, keeping its
  bodies.
---
 configure.ac  |  3 ---
 libshouldbeinlibc/idvec-impgids.c | 14 +-
 libthreads/cthreads.c |  9 +++--
 3 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/configure.ac b/configure.ac
index 873ced8..e756496 100644
--- a/configure.ac
+++ b/configure.ac
@@ -156,9 +156,6 @@ else
 fi
 AC_SUBST(VERSIONING)
 
-# Check if libc contains getgrouplist and/or uselocale.
-AC_CHECK_FUNCS(getgrouplist uselocale)
-
 
 # From glibc HEAD, 2007-11-07.
 AC_CACHE_CHECK(for -fgnu89-inline, libc_cv_gnu89_inline, [dnl
diff --git a/libshouldbeinlibc/idvec-impgids.c b/libshouldbeinlibc/idvec-impgids.c
index 74d3cc1..d89f487 100644
--- a/libshouldbeinlibc/idvec-impgids.c
+++ b/libshouldbeinlibc/idvec-impgids.c
@@ -1,6 +1,6 @@
 /* Add gids implied by a user
 
-   Copyright (C) 1997, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1997, 2001, 2014 Free Software Foundation, Inc.
 
Written by Miles Bader 
 
@@ -56,7 +56,6 @@ _merge_implied_gids (struct idvec *implied_gids, uid_t uid)
 else
   {
 	struct idvec *cache = make_idvec ();
-#ifdef HAVE_GETGROUPLIST
 	gid_t _gids[NUM_STATIC_GIDS], *gids = _gids;
 	int maxgids = NUM_STATIC_GIDS;
 	int ngids = getgrouplist (pw->pw_name, pw->pw_gid, gids, &maxgids);
@@ -79,17 +78,6 @@ _merge_implied_gids (struct idvec *implied_gids, uid_t uid)
 	if (gids != _gids)
 	  free (gids);
 	  }
-#else
-#warning "getgrouplist() not available; supplementary group IDs unsupported."
-	if (! cache)
-	  err = ENOMEM;
-	else
-	  {
-	err = idvec_add_new (cache, pw->pw_gid);
-	if (err)
-	  idvec_free (cache);
-	  }
-#endif
 
 	if (! err)
 	  {
diff --git a/libthreads/cthreads.c b/libthreads/cthreads.c
index aef20be..1361b8b 100644
--- a/libthreads/cthreads.c
+++ b/libthreads/cthreads.c
@@ -150,10 +150,7 @@
 #include 
 #include 
 #include "cthread_internals.h"
-
-#ifdef HAVE_USELOCALE
-# include 
-#endif
+#include 
 
 /*
  * Thread status bits.
@@ -292,11 +289,11 @@ cthread_body(cproc_t self)
 /*
  * Execute the fork request.
  */
-#ifdef HAVE_USELOCALE
+
 			/* A fresh thread needs to be bound to the
    global locale.  */
 			  	uselocale (LC_GLOBAL_LOCALE);
-#endif
+
 t->result = (*(t->func))(t->arg);
 			}
 			/*
-- 
1.8.4