Re: [PATCH v3 57/60] loader: rework handling of pci.ids and usb.ids

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 12, 2015 at 06:11:18PM +0100, Daniel P. Berrange wrote:
> Currently we have the option to download pci.ids/usb.ids or
> symlink to the distro provided version given to configure.
> 
> Change configure so that it searches for the files in a
> variety of expected locations. This ensures we always use
> the external files, in any modern Linux distro, without
> the user needing to give an arg. We look for them in
> 
>    /usr/share/hwdata/{pci.ids,usb.ids} (RHEL/Fedora)
>    /usr/share/misc/{pci.ids,usb.ids}   (Ubuntu/Debian/Gentoo)
>    /usr/share/{pci.ids,usb.ids}        (SLES/OpenSuse)
> 
> Instead of loading the pci.ids/usb.ids files as part of
> the main database file enumeration process, explicitly
> load them from their expected location. This avoids the
> need to symlink the distro provided files into the database
> dir.

I would probably have split the configure.ac/.spec changes from the
OsinfoLoader changes, but fine with me either way, changes look good.

Christophe

> 
> Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> ---
>  configure.ac            |  79 ++++++++++++++++++++++++++++-----
>  data/Makefile.am        |  32 ++++----------
>  libosinfo.spec.in       |   5 +--
>  mingw-libosinfo.spec.in |   8 ++--
>  osinfo/osinfo_loader.c  | 114 ++++++++++++++++++++++++++++++++++--------------
>  5 files changed, 162 insertions(+), 76 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 465a16c..a7eaf26 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -135,25 +135,80 @@ fi
>  AC_SUBST(COVERAGE_CFLAGS)
>  AC_SUBST(COVERAGE_LDFLAGS)
>  
> -# Path to the usb.ids file -- to know if we use one shipped with another
> -# package, or an internal file
> +
> +USB_ID_FILES="/usr/share/usb.ids /usr/share/misc/usb.ids /usr/share/hwdata/usb.ids"
> +
>  AC_ARG_WITH(usb-ids-path,
>                [AC_HELP_STRING([--with-usb-ids-path],
> -                              [Specify the path to usb.ids @<:@default=(internal)@:>@])],,
> -                              [with_usb_ids_path="\${usb_databasedir}/usb.ids"])
> +                              [Specify the path to usb.ids @<:@default=(internal)@:>@])])
> +
> +AC_MSG_CHECKING([location of usb.ids database])
> +local_usb_ids=0
> +if test -z "$with_usb_ids_path"
> +then
> +  if test $host = $build
> +  then
> +    for FILE in $USB_ID_FILES
> +    do
> +      if test -f $FILE
> +      then
> +        with_usb_ids_path="$FILE"
> +        break
> +      fi
> +    done
> +  fi
> +
> +  if test -z "$with_usb_ids_path"
> +  then
> +    local_usb_ids=1
> +  fi
> +fi
> +AM_CONDITIONAL([LOCAL_USB_IDS], [test "$local_usb_ids" = "1"])
> +if test -n "$with_usb_ids_path"
> +then
> +  AC_DEFINE_UNQUOTED([USB_IDS], ["$with_usb_ids_path"], ["location of usb.ids database"])
> +  AC_MSG_RESULT([$with_usb_ids_path])
> +else
> +  AC_MSG_RESULT([<built-in>])
> +fi
>  
> -AM_CONDITIONAL(USE_INTERNAL_USB_IDS, test "x$with_usb_ids_path" = "x\${usb_databasedir}/usb.ids")
> -AC_SUBST([USB_IDS], ["$with_usb_ids_path"])
>  
> -# Path to the pci.ids file -- to know if we use one shipped with another
> -# package, or an internal file
> +PCI_ID_FILES="/usr/share/pci.ids /usr/share/misc/pci.ids /usr/share/hwdata/pci.ids"
> +
>  AC_ARG_WITH(pci-ids-path,
>                [AC_HELP_STRING([--with-pci-ids-path],
> -                              [Specify the path to pci.ids @<:@default=(internal)@:>@])],,
> -                              [with_pci_ids_path="\${pci_databasedir}/pci.ids"])
> +                              [Specify the path to pci.ids @<:@default=(internal)@:>@])])
> +
> +AC_MSG_CHECKING([location of pci.ids database])
> +local_pci_ids=0
> +if test -z "$with_pci_ids_path"
> +then
> +  if test $host = $build
> +  then
> +    for FILE in $PCI_ID_FILES
> +    do
> +      if test -f $FILE
> +      then
> +        with_pci_ids_path="$FILE"
> +        break
> +      fi
> +    done
> +  fi
> +
> +  if test -z "$with_pci_ids_path"
> +  then
> +    local_pci_ids=1
> +  fi
> +fi
> +AM_CONDITIONAL([LOCAL_PCI_IDS], [test "$local_pci_ids" = "1"])
> +if test -n "$with_pci_ids_path"
> +then
> +  AC_DEFINE_UNQUOTED([PCI_IDS], ["$with_pci_ids_path"], ["location of pci.ids database"])
> +  AC_MSG_RESULT([$with_pci_ids_path])
> +else
> +  AC_MSG_RESULT([<built-in>])
> +fi
>  
> -AM_CONDITIONAL(USE_INTERNAL_PCI_IDS, test "x$with_pci_ids_path" = "x\${pci_databasedir}/pci.ids")
> -AC_SUBST([PCI_IDS], ["$with_pci_ids_path"])
>  
>  # Setup GLIB_MKENUMS to use glib-mkenums even if GLib is uninstalled.
>  GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
> diff --git a/data/Makefile.am b/data/Makefile.am
> index 2001b42..ff0e84f 100644
> --- a/data/Makefile.am
> +++ b/data/Makefile.am
> @@ -1,36 +1,20 @@
> -INSTALL_DATA_HOOK_DEPS =
>  
>  SUBDIRS = datamap device os platform install-script schemas
> -EXTRA_DIST = usb.ids pci.ids
> -CLEANFILES = usb.ids pci.ids
>  
> -if USE_INTERNAL_USB_IDS
> +CLEANFILES =
> +
> +if LOCAL_USB_IDS
>  usb_database_DATA = usb.ids
> -usb_databasedir = $(pkgdatadir)/db/
> +usb_databasedir = $(pkgdatadir)/
>  usb.ids:
>  	-wget -q -O $@ http://www.linux-usb.org/usb.ids
> -else
> -usb_ids_install:
> -	($(MKDIR_P) $(DESTDIR)$(pkgdatadir)/db && \
> -	 cd $(DESTDIR)$(pkgdatadir)/db/ && \
> -	 rm -f usb.ids && \
> -	 $(LN_S) $(USB_IDS) usb.ids)
> -INSTALL_DATA_HOOK_DEPS += usb_ids_install
> +CLEANFILES += usb.ids
>  endif
>  
> -if USE_INTERNAL_PCI_IDS
> +if LOCAL_PCI_IDS
>  pci_database_DATA = pci.ids
> -pci_databasedir = $(pkgdatadir)/db/
> +pci_databasedir = $(pkgdatadir)/
>  pci.ids:
>  	-wget -q -O $@ http://pciids.sourceforge.net/v2.2/pci.ids
> -else
> -pci_ids_install:
> -	($(MKDIR_P) $(DESTDIR)$(pkgdatadir)/db && \
> -	 cd $(DESTDIR)$(pkgdatadir)/db/ && \
> -	 rm -f pci.ids && \
> -	 $(LN_S) $(PCI_IDS) pci.ids)
> -INSTALL_DATA_HOOK_DEPS += pci_ids_install
> +CLEANFILES += pci.ids
>  endif
> -
> -
> -install-data-hook: $(INSTALL_DATA_HOOK_DEPS)
> diff --git a/libosinfo.spec.in b/libosinfo.spec.in
> index 8ef688a..0feed84 100644
> --- a/libosinfo.spec.in
> +++ b/libosinfo.spec.in
> @@ -28,6 +28,7 @@ BuildRequires: vala
>  BuildRequires: vala-tools
>  BuildRequires: libsoup-devel
>  BuildRequires: /usr/bin/pod2man
> +BuildRequires: hwdata
>  %if %{with_gir}
>  BuildRequires: gobject-introspection-devel
>  %endif
> @@ -74,7 +75,7 @@ This package provides the Vala bindings for libosinfo library.
>  %define gir_arg --enable-introspection=no
>  %endif
>  
> -%configure %{gir_arg} --enable-vala=yes --with-usb-ids-path=/usr/share/hwdata/usb.ids --with-pci-ids-path=/usr/share/hwdata/pci.ids
> +%configure %{gir_arg} --enable-vala=yes
>  %__make %{?_smp_mflags} V=1
>  
>  chmod a-x examples/*.js examples/*.py
> @@ -107,8 +108,6 @@ rm -fr %{buildroot}
>  %dir %{_datadir}/libosinfo/
>  %dir %{_datadir}/libosinfo/db/
>  %dir %{_datadir}/libosinfo/schemas/
> -%{_datadir}/libosinfo/db/usb.ids
> -%{_datadir}/libosinfo/db/pci.ids
>  %{_datadir}/libosinfo/db/datamap
>  %{_datadir}/libosinfo/db/device
>  %{_datadir}/libosinfo/db/os
> diff --git a/mingw-libosinfo.spec.in b/mingw-libosinfo.spec.in
> index 2529471..16c5699 100644
> --- a/mingw-libosinfo.spec.in
> +++ b/mingw-libosinfo.spec.in
> @@ -103,8 +103,8 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_datadir}/gtk-doc
>  %dir %{mingw32_datadir}/libosinfo
>  %dir %{mingw32_datadir}/libosinfo/db
>  %dir %{mingw32_datadir}/libosinfo/schemas
> -%{mingw32_datadir}/libosinfo/db/usb.ids
> -%{mingw32_datadir}/libosinfo/db/pci.ids
> +%{mingw32_datadir}/libosinfo/usb.ids
> +%{mingw32_datadir}/libosinfo/pci.ids
>  %{mingw32_datadir}/libosinfo/db/datamap
>  %{mingw32_datadir}/libosinfo/db/device
>  %{mingw32_datadir}/libosinfo/db/os
> @@ -128,8 +128,8 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_datadir}/gtk-doc
>  %dir %{mingw64_datadir}/libosinfo
>  %dir %{mingw64_datadir}/libosinfo/db
>  %dir %{mingw64_datadir}/libosinfo/schemas
> -%{mingw64_datadir}/libosinfo/db/usb.ids
> -%{mingw64_datadir}/libosinfo/db/pci.ids
> +%{mingw64_datadir}/libosinfo/usb.ids
> +%{mingw64_datadir}/libosinfo/pci.ids
>  %{mingw64_datadir}/libosinfo/db/datamap
>  %{mingw64_datadir}/libosinfo/db/device
>  %{mingw64_datadir}/libosinfo/db/os
> diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
> index c516c92..f7b841d 100644
> --- a/osinfo/osinfo_loader.c
> +++ b/osinfo/osinfo_loader.c
> @@ -38,6 +38,13 @@
>  #include "osinfo_install_script_private.h"
>  #include "osinfo_device_driver_private.h"
>  
> +#ifndef USB_IDS
> +#define USB_IDS PKG_DATA_DIR "/usb.ids"
> +#endif
> +#ifndef PCI_IDS
> +#define PCI_IDS PKG_DATA_DIR "/pci.ids"
> +#endif
> +
>  G_DEFINE_TYPE(OsinfoLoader, osinfo_loader, G_TYPE_OBJECT);
>  
>  #define OSINFO_LOADER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OSINFO_TYPE_LOADER, OsinfoLoaderPrivate))
> @@ -1753,22 +1760,6 @@ osinfo_loader_process_file_reg_xml(OsinfoLoader *loader,
>  }
>  
>  
> -static void
> -osinfo_loader_process_file(OsinfoLoader *loader,
> -                           GFile *file,
> -                           GError **err)
> -{
> -    const gchar *name = g_file_get_basename(file);
> -
> -    if (g_str_has_suffix(name, ".xml"))
> -        osinfo_loader_process_file_reg_xml(loader, file, err);
> -    else if (strcmp(name, "usb.ids") == 0)
> -        osinfo_loader_process_file_reg_usb(loader, file, err);
> -    else if (strcmp(name, "pci.ids") == 0)
> -        osinfo_loader_process_file_reg_pci(loader, file, err);
> -}
> -
> -
>  static GList *osinfo_loader_find_files(OsinfoLoader *loader,
>                                         GFile *file,
>                                         GError **err)
> @@ -1796,9 +1787,7 @@ static GList *osinfo_loader_find_files(OsinfoLoader *loader,
>          GFileType type = g_file_info_get_attribute_uint32(child,
>                                                            G_FILE_ATTRIBUTE_STANDARD_TYPE);
>          if (type == G_FILE_TYPE_REGULAR) {
> -            if (g_str_has_suffix(name, ".xml") ||
> -                g_str_equal(name, "usb.ids") ||
> -                g_str_equal(name, "pci.ids"))
> +            if (g_str_has_suffix(name, ".xml"))
>                  files = g_list_append(files, g_object_ref(ent));
>          } else if (type == G_FILE_TYPE_DIRECTORY) {
>              GList *subfiles = osinfo_loader_find_files(loader, ent, &error);
> @@ -1821,6 +1810,12 @@ static GList *osinfo_loader_find_files(OsinfoLoader *loader,
>  }
>  
>  
> +typedef enum {
> +    OSINFO_DATA_FORMAT_NATIVE,
> +    OSINFO_DATA_FORMAT_PCI_IDS,
> +    OSINFO_DATA_FORMAT_USB_IDS,
> +} OsinfoLoaderDataFormat;
> +
>  static void osinfo_loader_process_list(OsinfoLoader *loader,
>                                         GFile **dirs,
>                                         GError **err)
> @@ -1830,24 +1825,39 @@ static void osinfo_loader_process_list(OsinfoLoader *loader,
>      gpointer key, value;
>  
>      while (dirs && *dirs) {
> -        GList *files = osinfo_loader_find_files(loader, *dirs, &lerr);
> -        GList *tmp;
> -        if (lerr) {
> -            g_propagate_error(err, lerr);
> -            return;
> -        }
> +        OsinfoLoaderDataFormat fmt = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(*dirs), "data-format"));
>  
> -        tmp = files;
> -        while (tmp) {
> -            osinfo_loader_process_file(loader, tmp->data, &lerr);
> +        switch (fmt) {
> +        case OSINFO_DATA_FORMAT_NATIVE: {
> +            GList *files = osinfo_loader_find_files(loader, *dirs, &lerr);
> +            GList *tmp;
>              if (lerr) {
>                  g_propagate_error(err, lerr);
> -                break;
> +                return;
> +            }
> +
> +            tmp = files;
> +            while (tmp) {
> +                osinfo_loader_process_file_reg_xml(loader, tmp->data, &lerr);
> +                if (lerr) {
> +                    g_propagate_error(err, lerr);
> +                    break;
> +                }
> +                tmp = tmp->next;
>              }
> -            tmp = tmp->next;
> +            g_list_foreach(files, (GFunc)g_object_unref, NULL);
> +            g_list_free(files);
> +
> +        }   break;
> +
> +        case OSINFO_DATA_FORMAT_PCI_IDS:
> +            osinfo_loader_process_file_reg_pci(loader, *dirs, &lerr);
> +            break;
> +
> +        case OSINFO_DATA_FORMAT_USB_IDS:
> +            osinfo_loader_process_file_reg_usb(loader, *dirs, &lerr);
> +            break;
>          }
> -        g_list_foreach(files, (GFunc)g_object_unref, NULL);
> -        g_list_free(files);
>  
>          if (lerr) {
>              break;
> @@ -1898,6 +1908,8 @@ void osinfo_loader_process_path(OsinfoLoader *loader,
>          g_file_new_for_path(path),
>          NULL,
>      };
> +    g_object_set_data(G_OBJECT(dirs[0]), "data-format",
> +                      GINT_TO_POINTER(OSINFO_DATA_FORMAT_NATIVE));
>      osinfo_loader_process_list(loader, dirs, err);
>      g_object_unref(dirs[0]);
>  }
> @@ -1921,11 +1933,31 @@ void osinfo_loader_process_uri(OsinfoLoader *loader,
>          g_file_new_for_uri(uri),
>          NULL,
>      };
> +    g_object_set_data(G_OBJECT(dirs[0]), "data-format",
> +                      GINT_TO_POINTER(OSINFO_DATA_FORMAT_NATIVE));
>      osinfo_loader_process_list(loader, dirs, err);
>      g_object_unref(dirs[0]);
>  }
>  
>  
> +static GFile *osinfo_loader_get_pci_path(void)
> +{
> +    GFile *ids = g_file_new_for_path(PCI_IDS);
> +    g_object_set_data(G_OBJECT(ids), "data-format",
> +                      GINT_TO_POINTER(OSINFO_DATA_FORMAT_PCI_IDS));
> +    return ids;
> +}
> +
> +
> +static GFile *osinfo_loader_get_usb_path(void)
> +{
> +    GFile *ids = g_file_new_for_path(USB_IDS);
> +    g_object_set_data(G_OBJECT(ids), "data-format",
> +                      GINT_TO_POINTER(OSINFO_DATA_FORMAT_USB_IDS));
> +    return ids;
> +}
> +
> +
>  static GFile *osinfo_loader_get_system_path(void)
>  {
>      GFile *file;
> @@ -1936,13 +1968,19 @@ static GFile *osinfo_loader_get_system_path(void)
>  
>      dbdir = g_strdup_printf("%s/db", path);
>      file = g_file_new_for_path(dbdir);
> +    g_object_set_data(G_OBJECT(file), "data-format",
> +                      GINT_TO_POINTER(OSINFO_DATA_FORMAT_NATIVE));
>      g_free(dbdir);
>      return file;
>  }
>  
>  static GFile *osinfo_loader_get_local_path(void)
>  {
> -    return g_file_new_for_path(SYS_CONF_DIR "/libosinfo/db");
> +    GFile *file;
> +    file = g_file_new_for_path(SYS_CONF_DIR "/libosinfo/db");
> +    g_object_set_data(G_OBJECT(file), "data-format",
> +                      GINT_TO_POINTER(OSINFO_DATA_FORMAT_NATIVE));
> +    return file;
>  }
>  
>  static GFile *osinfo_loader_get_user_path(void)
> @@ -1953,6 +1991,8 @@ static GFile *osinfo_loader_get_user_path(void)
>  
>      dbdir = g_strdup_printf("%s/libosinfo/db", configdir);
>      file = g_file_new_for_path(dbdir);
> +    g_object_set_data(G_OBJECT(file), "data-format",
> +                      GINT_TO_POINTER(OSINFO_DATA_FORMAT_NATIVE));
>      g_free(dbdir);
>      return file;
>  }
> @@ -1960,6 +2000,8 @@ static GFile *osinfo_loader_get_user_path(void)
>  void osinfo_loader_process_default_path(OsinfoLoader *loader, GError **err)
>  {
>      GFile *dirs[] = {
> +        osinfo_loader_get_pci_path(),
> +        osinfo_loader_get_usb_path(),
>          osinfo_loader_get_system_path(),
>          osinfo_loader_get_local_path(),
>          osinfo_loader_get_user_path(),
> @@ -1970,6 +2012,8 @@ void osinfo_loader_process_default_path(OsinfoLoader *loader, GError **err)
>      g_object_unref(dirs[0]);
>      g_object_unref(dirs[1]);
>      g_object_unref(dirs[2]);
> +    g_object_unref(dirs[3]);
> +    g_object_unref(dirs[4]);
>  }
>  
>  /**
> @@ -1983,12 +2027,16 @@ void osinfo_loader_process_system_path(OsinfoLoader *loader,
>                                         GError **err)
>  {
>      GFile *dirs[] = {
> +        osinfo_loader_get_pci_path(),
> +        osinfo_loader_get_usb_path(),
>          osinfo_loader_get_system_path(),
>          NULL,
>      };
>  
>      osinfo_loader_process_list(loader, dirs, err);
>      g_object_unref(dirs[0]);
> +    g_object_unref(dirs[1]);
> +    g_object_unref(dirs[2]);
>  }
>  
>  void osinfo_loader_process_local_path(OsinfoLoader *loader, GError **err)
> -- 
> 2.4.3
> 
> _______________________________________________
> Libosinfo mailing list
> Libosinfo@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libosinfo

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux