[systemd-devel] [PATCH 1/2] libsystemd: add sd-hwdb library

2014-12-03 Thread Tom Gundersen
This is libudev-hwdb, but decoupled from libudev and in the libsystemd style.

The core code is unchanged, apart from the following minor changes:

 - hwdb.bin located in /**/systemd/hwdb/ take preference over the ones located
   in /**/udev/
 - properties are stored internally in an OrderedHashmap, rather than a
   linked list.
 - a new API call allows individual properties to be queried directly, rather
   than iterating over them all
 - the iteration over properties have been moved inside the library, rather than
   exposing a list directly
 - the unused 'flags' parameter was dropped
---
 Makefile.am|   7 +-
 src/libsystemd/sd-hwdb/Makefile|   1 +
 src/libsystemd/sd-hwdb/hwdb-internal.h |  70 +
 src/libsystemd/sd-hwdb/hwdb-util.h |  31 +++
 src/libsystemd/sd-hwdb/sd-hwdb.c   | 471 +
 src/systemd/sd-hwdb.h  |  46 
 6 files changed, 625 insertions(+), 1 deletion(-)
 create mode 12 src/libsystemd/sd-hwdb/Makefile
 create mode 100644 src/libsystemd/sd-hwdb/hwdb-internal.h
 create mode 100644 src/libsystemd/sd-hwdb/hwdb-util.h
 create mode 100644 src/libsystemd/sd-hwdb/sd-hwdb.c
 create mode 100644 src/systemd/sd-hwdb.h

diff --git a/Makefile.am b/Makefile.am
index d4d96e1..f3be5fd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -217,6 +217,7 @@ AM_CPPFLAGS = \
-I $(top_srcdir)/src/libsystemd/sd-event \
-I $(top_srcdir)/src/libsystemd/sd-rtnl \
-I $(top_srcdir)/src/libsystemd/sd-network \
+   -I $(top_srcdir)/src/libsystemd/sd-hwdb \
-I $(top_srcdir)/src/libsystemd-network \
-I $(top_srcdir)/src/libsystemd-terminal \
$(OUR_CPPFLAGS)
@@ -2604,6 +2605,7 @@ libsystemd_internal_la_SOURCES = \
src/systemd/sd-daemon.h \
src/systemd/sd-path.h \
src/systemd/sd-network.h \
+   src/systemd/sd-hwdb.h \
src/libsystemd/sd-bus/sd-bus.c \
src/libsystemd/sd-bus/bus-control.c \
src/libsystemd/sd-bus/bus-control.h \
@@ -2662,7 +2664,10 @@ libsystemd_internal_la_SOURCES = \
src/libsystemd/sd-path/sd-path.c \
src/libsystemd/sd-network/sd-network.c \
src/libsystemd/sd-network/network-util.h \
-   src/libsystemd/sd-network/network-util.c
+   src/libsystemd/sd-network/network-util.c \
+   src/libsystemd/sd-hwdb/sd-hwdb.c \
+   src/libsystemd/sd-hwdb/hwdb-util.h \
+   src/libsystemd/sd-hwdb/hwdb-intenal.h
 
 nodist_libsystemd_internal_la_SOURCES = \
src/libsystemd/libsystemd.sym
diff --git a/src/libsystemd/sd-hwdb/Makefile b/src/libsystemd/sd-hwdb/Makefile
new file mode 12
index 000..94aaae2
--- /dev/null
+++ b/src/libsystemd/sd-hwdb/Makefile
@@ -0,0 +1 @@
+../../Makefile
\ No newline at end of file
diff --git a/src/libsystemd/sd-hwdb/hwdb-internal.h 
b/src/libsystemd/sd-hwdb/hwdb-internal.h
new file mode 100644
index 000..fedccde
--- /dev/null
+++ b/src/libsystemd/sd-hwdb/hwdb-internal.h
@@ -0,0 +1,70 @@
+/***
+  This file is part of systemd.
+
+  Copyright 2012 Kay Sievers k...@vrfy.org
+
+  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
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see http://www.gnu.org/licenses/.
+***/
+#pragma once
+
+#include sparse-endian.h
+
+#define HWDB_SIG { 'K', 'S', 'L', 'P', 'H', 'H', 'R', 'H' }
+
+/* on-disk trie objects */
+struct trie_header_f {
+uint8_t signature[8];
+
+/* version of tool which created the file */
+le64_t tool_version;
+le64_t file_size;
+
+/* size of structures to allow them to grow */
+le64_t header_size;
+le64_t node_size;
+le64_t child_entry_size;
+le64_t value_entry_size;
+
+/* offset of the root trie node */
+le64_t nodes_root_off;
+
+/* size of the nodes and string section */
+le64_t nodes_len;
+le64_t strings_len;
+} _packed_;
+
+struct trie_node_f {
+/* prefix of lookup string, shared by all children  */
+le64_t prefix_off;
+/* size of children entry array appended to the node */
+uint8_t children_count;
+uint8_t padding[7];
+/* size of value entry array appended to the node */
+le64_t values_count;
+} _packed_;
+
+/* array of child entries, follows directly the node record */
+struct trie_child_entry_f {
+/* index of the child node */
+uint8_t c;
+uint8_t padding[7];
+/* offset of the child node */
+ 

Re: [systemd-devel] [PATCH 1/2] libsystemd: add sd-hwdb library

2014-12-03 Thread Greg KH
On Wed, Dec 03, 2014 at 10:11:40PM +0100, Tom Gundersen wrote:
 This is libudev-hwdb, but decoupled from libudev and in the libsystemd style.
 
 The core code is unchanged, apart from the following minor changes:
 
  - hwdb.bin located in /**/systemd/hwdb/ take preference over the ones located
in /**/udev/
  - properties are stored internally in an OrderedHashmap, rather than a
linked list.
  - a new API call allows individual properties to be queried directly, rather
than iterating over them all
  - the iteration over properties have been moved inside the library, rather 
 than
exposing a list directly
  - the unused 'flags' parameter was dropped

Why pull this apart?  Are other applications wanting to use this?

thanks,

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


Re: [systemd-devel] [PATCH 1/2] libsystemd: add sd-hwdb library

2014-12-03 Thread Tom Gundersen
On Wed, Dec 3, 2014 at 10:19 PM, Greg KH gre...@linuxfoundation.org wrote:
 On Wed, Dec 03, 2014 at 10:11:40PM +0100, Tom Gundersen wrote:
 This is libudev-hwdb, but decoupled from libudev and in the libsystemd style.

 The core code is unchanged, apart from the following minor changes:

  - hwdb.bin located in /**/systemd/hwdb/ take preference over the ones 
 located
in /**/udev/
  - properties are stored internally in an OrderedHashmap, rather than a
linked list.
  - a new API call allows individual properties to be queried directly, rather
than iterating over them all
  - the iteration over properties have been moved inside the library, rather 
 than
exposing a list directly
  - the unused 'flags' parameter was dropped

 Why pull this apart?

We'd like to move the libudev API closer to the libsystemd one, and as
the hwdb stuff is actually completely separate from the rest of
libudev, it is a nice place to start I thought. The benefit is rather
minor (consistency of API and improved error handling), but still
worth-while I think.

One point though, which I forgot to mention in the patch description,
is that one more change is made: I dropped the unused struct udev
context and didn't replace it with anything else. I think this fits
with how other things are done in libsystemd, but it _is_ nice to have
a context around for future extensions... What do you think Kay?

 Are other applications wanting to use this?

A couple applications use hwdb directly yes, and in some cases without
using libudev for anything else. If people start using dbus more in
place of the userspace-to-userspace udev transport, then I guess we'll
have more cases of programs using hwdb directly without otherwise
needing libudev, so having these separate (at least their API, if not
the actual .so) makes sense I think. There have been requests for
splitting out hwdb before [0], but I don't think these patches help
much for what they want (and hwdb really does not make sense in a
non-Linux setting anyway, so I'm not really convinced by that feature
request at all).

Thanks for taking a look!

Cheers,

Tom

[0]: https://bugs.freedesktop.org/show_bug.cgi?id=72562
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH 1/2] libsystemd: add sd-hwdb library

2014-12-03 Thread Lennart Poettering
On Thu, 04.12.14 00:57, Tom Gundersen (t...@jklm.no) wrote:

 On Wed, Dec 3, 2014 at 10:19 PM, Greg KH gre...@linuxfoundation.org wrote:
  On Wed, Dec 03, 2014 at 10:11:40PM +0100, Tom Gundersen wrote:
  This is libudev-hwdb, but decoupled from libudev and in the libsystemd 
  style.
 
  The core code is unchanged, apart from the following minor changes:
 
   - hwdb.bin located in /**/systemd/hwdb/ take preference over the ones 
  located
 in /**/udev/
   - properties are stored internally in an OrderedHashmap, rather than a
 linked list.
   - a new API call allows individual properties to be queried directly, 
  rather
 than iterating over them all
   - the iteration over properties have been moved inside the library, 
  rather than
 exposing a list directly
   - the unused 'flags' parameter was dropped
 
  Why pull this apart?
 
 We'd like to move the libudev API closer to the libsystemd one, and as
 the hwdb stuff is actually completely separate from the rest of
 libudev, it is a nice place to start I thought. The benefit is rather
 minor (consistency of API and improved error handling), but still
 worth-while I think.
 
 One point though, which I forgot to mention in the patch description,
 is that one more change is made: I dropped the unused struct udev
 context and didn't replace it with anything else. I think this fits
 with how other things are done in libsystemd, but it _is_ nice to have
 a context around for future extensions... What do you think Kay?

Well, if you have sd_hwdb now as new context object, that should be
more than enough.

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 1/2] libsystemd: add sd-hwdb library

2014-12-03 Thread Greg KH
On Thu, Dec 04, 2014 at 12:57:53AM +0100, Tom Gundersen wrote:
 On Wed, Dec 3, 2014 at 10:19 PM, Greg KH gre...@linuxfoundation.org wrote:
  On Wed, Dec 03, 2014 at 10:11:40PM +0100, Tom Gundersen wrote:
  This is libudev-hwdb, but decoupled from libudev and in the libsystemd 
  style.
 
  The core code is unchanged, apart from the following minor changes:
 
   - hwdb.bin located in /**/systemd/hwdb/ take preference over the ones 
  located
 in /**/udev/
   - properties are stored internally in an OrderedHashmap, rather than a
 linked list.
   - a new API call allows individual properties to be queried directly, 
  rather
 than iterating over them all
   - the iteration over properties have been moved inside the library, 
  rather than
 exposing a list directly
   - the unused 'flags' parameter was dropped
 
  Why pull this apart?
 
 We'd like to move the libudev API closer to the libsystemd one, and as
 the hwdb stuff is actually completely separate from the rest of
 libudev, it is a nice place to start I thought. The benefit is rather
 minor (consistency of API and improved error handling), but still
 worth-while I think.

That makes sense.

  Are other applications wanting to use this?
 
 A couple applications use hwdb directly yes, and in some cases without
 using libudev for anything else.

I maintain one such application, usbutils, that only depends on libudev
for the database, so this will be a nice change for it to make.

 If people start using dbus more in
 place of the userspace-to-userspace udev transport, then I guess we'll
 have more cases of programs using hwdb directly without otherwise
 needing libudev, so having these separate (at least their API, if not
 the actual .so) makes sense I think. There have been requests for
 splitting out hwdb before [0], but I don't think these patches help
 much for what they want (and hwdb really does not make sense in a
 non-Linux setting anyway, so I'm not really convinced by that feature
 request at all).

There have been some requests in Gentoo to split this out as well, so
this will make those users happy.

thanks for doing this.

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