Re: [systemd-devel] [PATCH 04/11] tmpfiles: attach an array of items to each path

2015-01-27 Thread Lennart Poettering
On Mon, 19.01.15 01:20, Zbigniew Jędrzejewski-Szmek (zbys...@in.waw.pl) wrote:

 The data structure used by tmpfiles is changed: instead of hashmaps
 mapping {path → Item*} we now have hashmaps containing
 {path - ItemArray}, where ItemArray contains a pointer
 to an array of Items.

I figure one of those days we really should add a proper MultiHashmap
type or so, that can map one key to multiple values. There are quite a
few cases we could have used this so far, and this is the next one.

So far we usually resorted to using a hashmap that points to a linked
list of items, using the LIST_FIELDS macros for the list. That has the
nice effect that ignoring the list makes the this multi-map behave
exactly like a normal map, i.e. it points to one valid object...

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH 04/11] tmpfiles: attach an array of items to each path

2015-01-27 Thread Zbigniew Jędrzejewski-Szmek
On Wed, Jan 28, 2015 at 02:59:24AM +0100, Lennart Poettering wrote:
 On Mon, 19.01.15 01:20, Zbigniew Jędrzejewski-Szmek (zbys...@in.waw.pl) wrote:
 
  The data structure used by tmpfiles is changed: instead of hashmaps
  mapping {path → Item*} we now have hashmaps containing
  {path - ItemArray}, where ItemArray contains a pointer
  to an array of Items.
 
 I figure one of those days we really should add a proper MultiHashmap
 type or so, that can map one key to multiple values. There are quite a
 few cases we could have used this so far, and this is the next one.
 
 So far we usually resorted to using a hashmap that points to a linked
 list of items, using the LIST_FIELDS macros for the list. That has the
 nice effect that ignoring the list makes the this multi-map behave
 exactly like a normal map, i.e. it points to one valid object...
[I pushed the code a while ago.]

Yeah, that would work too, probably nicer than my array-based approach.
Fortunately this should be a narrow change to the code.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH 04/11] tmpfiles: attach an array of items to each path

2015-01-18 Thread Greg KH
On Mon, Jan 19, 2015 at 01:20:37AM +0100, Zbigniew Jędrzejewski-Szmek wrote:
 The data structure used by tmpfiles is changed: instead of hashmaps
 mapping {path → Item*} we now have hashmaps containing
 {path - ItemArray}, where ItemArray contains a pointer
 to an array of Items.
 
 For current code it doesn't matter much, but when we add new types it
 is easier to simply add a new Item for a given path, then to coalesce
 multiple lines into one Item.
 
 In the future, this change will also make it possible to remember the
 file and line where each Item originates, and use that in reporting
 errors. Currently this is not possible, since each Item can be created
 from multiple lines.
 ---
  man/tmpfiles.d.xml  |  13 +-
  src/tmpfiles/tmpfiles.c | 308 
 
  2 files changed, 160 insertions(+), 161 deletions(-)

Oh, I like this, nice job.  As someone who has tried to add new
functionalty to this code, this looks to make it much easier to do in
the future, if it is needed.

Bonus being it's the same number of lines :)

good work,

greg k-h
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 04/11] tmpfiles: attach an array of items to each path

2015-01-18 Thread Zbigniew Jędrzejewski-Szmek
The data structure used by tmpfiles is changed: instead of hashmaps
mapping {path → Item*} we now have hashmaps containing
{path - ItemArray}, where ItemArray contains a pointer
to an array of Items.

For current code it doesn't matter much, but when we add new types it
is easier to simply add a new Item for a given path, then to coalesce
multiple lines into one Item.

In the future, this change will also make it possible to remember the
file and line where each Item originates, and use that in reporting
errors. Currently this is not possible, since each Item can be created
from multiple lines.
---
 man/tmpfiles.d.xml  |  13 +-
 src/tmpfiles/tmpfiles.c | 308 
 2 files changed, 160 insertions(+), 161 deletions(-)

diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml
index 9fd5913d83..8d806a41ea 100644
--- a/man/tmpfiles.d.xml
+++ b/man/tmpfiles.d.xml
@@ -288,16 +288,9 @@
 
 varlistentry
   termvarnamet/varname/term
-  listitemparaSet extended attributes on item. It may be
-  used in conjunction with other types (only
-  varnamed/varname, varnameD/varname,
-  varnamef/varname, varnameF/varname,
-  varnameL/varname, varnamep/varname,
-  varnamec/varname, varnameb/varname, makes sense).
-  If used as a standalone line, then
-  commandsystemd-tmpfiles/command will try to set extended
-  attributes on specified path.  This can be especially used
-  to set SMACK labels.  /para/listitem
+  listitemparaSet extended attributes on the specified
+  path. This can be useful for setting SMACK labels.
+  /para/listitem
 /varlistentry
   /variablelist
 
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 84d778a08f..c44dfaf1d2 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -4,6 +4,7 @@
   This file is part of systemd.
 
   Copyright 2010 Lennart Poettering, Kay Sievers
+  Copyright 2015 Zbigniew Jędrzejewski-Szmek
 
   systemd is free software; you can redistribute it and/or modify it
   under the terms of the GNU Lesser General Public License as published by
@@ -113,6 +114,12 @@ typedef struct Item {
 bool done:1;
 } Item;
 
+typedef struct ItemArray {
+Item *items;
+size_t count;
+size_t size;
+} ItemArray;
+
 static bool arg_create = false;
 static bool arg_clean = false;
 static bool arg_remove = false;
@@ -141,13 +148,40 @@ static bool needs_glob(ItemType t) {
   RECURSIVE_RELABEL_PATH);
 }
 
+static bool takes_ownership(ItemType t) {
+return IN_SET(t,
+  CREATE_FILE,
+  TRUNCATE_FILE,
+  CREATE_DIRECTORY,
+  TRUNCATE_DIRECTORY,
+  CREATE_SUBVOLUME,
+  CREATE_FIFO,
+  CREATE_SYMLINK,
+  CREATE_CHAR_DEVICE,
+  CREATE_BLOCK_DEVICE,
+  COPY_FILES,
+
+  WRITE_FILE,
+  IGNORE_PATH,
+  IGNORE_DIRECTORY_PATH,
+  REMOVE_PATH,
+  RECURSIVE_REMOVE_PATH);
+}
+
 static struct Item* find_glob(Hashmap *h, const char *match) {
-Item *j;
+ItemArray *j;
 Iterator i;
 
-HASHMAP_FOREACH(j, h, i)
-if (fnmatch(j-path, match, FNM_PATHNAME|FNM_PERIOD) == 0)
-return j;
+HASHMAP_FOREACH(j, h, i) {
+unsigned n;
+
+for (n = 0; n  j-count; n++) {
+Item *item = j-items + n;
+
+if (fnmatch(item-path, match, 
FNM_PATHNAME|FNM_PERIOD) == 0)
+return item;
+}
+}
 
 return NULL;
 }
@@ -604,10 +638,6 @@ static int write_one_file(Item *i, const char *path) {
 if (r  0)
 return r;
 
-r = item_set_xattrs(i, i-path);
-if (r  0)
-return r;
-
 return 0;
 }
 
@@ -790,10 +820,6 @@ static int create_item(Item *i) {
 if (r  0)
 return r;
 
-r = item_set_xattrs(i, i-path);
-if (r  0)
-return r;
-
 break;
 
 case CREATE_FIFO:
@@ -834,10 +860,6 @@ static int create_item(Item *i) {
 if (r  0)
 return r;
 
-r = item_set_xattrs(i, i-path);
-if (r  0)
-return r;
-
 break;
 
 case CREATE_SYMLINK:
@@ -869,10 +891,6 @@ static int create_item(Item *i) {
 }
 }
 
-r = item_set_xattrs(i, i-path);
-if (r  0)
-   return r;
-
 break;
 
 case CREATE_BLOCK_DEVICE:
@@ -933,10