[PATCH] Prefix major/minor with gnu_dev_

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

 



In the latest glibc, major() and minor() functions are marked as
deprecated (glibc commit dbab6577):

  CC       util/libvirt_util_la-vircgroup.lo
util/vircgroup.c: In function 'virCgroupGetBlockDevString':
util/vircgroup.c:768:5: error: '__major_from_sys_types' is deprecated:
  In the GNU C Library, `major' is defined by <sys/sysmacros.h>.
  For historical compatibility, it is currently defined by
  <sys/types.h> as well, but we plan to remove this soon.
  To use `major', include <sys/sysmacros.h> directly.
  If you did not intend to use a system-defined macro `major',
  you should #undef it after including <sys/types.h>.
  [-Werror=deprecated-declarations]
     if (virAsprintf(&ret, "%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)) < 0)
     ^~
In file included from /usr/include/features.h:397:0,
                 from /usr/include/bits/libc-header-start.h:33,
                 from /usr/include/stdio.h:28,
                 from ../gnulib/lib/stdio.h:43,
                 from util/vircgroup.c:26:
/usr/include/sys/sysmacros.h:87:1: note: declared here
 __SYSMACROS_DEFINE_MAJOR (__SYSMACROS_FST_IMPL_TEMPL)
 ^

Applications are supposed to use gnu_dev_major() or
gnu_dev_minor() respectively.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/domain_audit.c  |  4 ++--
 src/lxc/lxc_controller.c | 10 +++++-----
 src/lxc/lxc_driver.c     | 26 +++++++++++++-------------
 src/util/vircgroup.c     | 10 +++++-----
 src/util/virutil.c       |  6 +++---
 tests/vircgroupmock.c    | 16 ++++++++--------
 6 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 53a58ac..d0bfa58 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -52,8 +52,8 @@ virDomainAuditGetRdev(const char *path)
 
     if (stat(path, &sb) == 0 &&
         (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode))) {
-        int maj = major(sb.st_rdev);
-        int min = minor(sb.st_rdev);
+        int maj = gnu_dev_major(sb.st_rdev);
+        int min = gnu_dev_minor(sb.st_rdev);
         ignore_value(virAsprintfQuiet(&ret, "%02X:%02X", maj, min));
     }
     return ret;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 825b4d4..3bf7eb2 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1520,7 +1520,7 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl)
                         LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0)
             goto cleanup;
 
-        dev_t dev = makedev(devs[i].maj, devs[i].min);
+        dev_t dev = gnu_dev_makedev(devs[i].maj, devs[i].min);
         if (mknod(path, S_IFCHR, dev) < 0 ||
             chmod(path, devs[i].mode)) {
             virReportSystemError(errno,
@@ -1592,7 +1592,7 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef,
     }
 
     VIR_DEBUG("Creating dev %s (%d,%d)",
-              dstfile, major(sb.st_rdev), minor(sb.st_rdev));
+              dstfile, gnu_dev_major(sb.st_rdev), gnu_dev_minor(sb.st_rdev));
     if (mknod(dstfile, mode, sb.st_rdev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
@@ -1672,7 +1672,7 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefPtr vmDef,
     mode = 0700 | S_IFBLK;
 
     VIR_DEBUG("Creating dev %s (%d,%d)", dst,
-              major(sb.st_rdev), minor(sb.st_rdev));
+              gnu_dev_major(sb.st_rdev), gnu_dev_minor(sb.st_rdev));
     if (mknod(dst, mode, sb.st_rdev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
@@ -1751,7 +1751,7 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr vmDef,
     mode = 0700 | S_IFCHR;
 
     VIR_DEBUG("Creating dev %s (%d,%d)", dst,
-              major(sb.st_rdev), minor(sb.st_rdev));
+              gnu_dev_major(sb.st_rdev), gnu_dev_minor(sb.st_rdev));
     if (mknod(dst, mode, sb.st_rdev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
@@ -1911,7 +1911,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
      * to that normally implied by the device name
      */
     VIR_DEBUG("Creating dev %s (%d,%d) from %s",
-              dst, major(sb.st_rdev), minor(sb.st_rdev), tmpsrc);
+              dst, gnu_dev_major(sb.st_rdev), gnu_dev_minor(sb.st_rdev), tmpsrc);
     if (mknod(dst, mode, sb.st_rdev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index da98b38..3fe79fd 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3714,7 +3714,7 @@ lxcDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
      * to that normally implied by the device name
      */
     VIR_DEBUG("Creating dev %s (%d,%d)",
-              data->file, major(data->dev), minor(data->dev));
+              data->file, gnu_dev_major(data->dev), gnu_dev_minor(data->dev));
     if (mknod(data->file, data->mode, data->dev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
@@ -3895,8 +3895,8 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
 
     if (virCgroupAllowDevice(priv->cgroup,
                              'b',
-                             major(sb.st_rdev),
-                             minor(sb.st_rdev),
+                             gnu_dev_major(sb.st_rdev),
+                             gnu_dev_minor(sb.st_rdev),
                              perms) < 0)
         goto cleanup;
 
@@ -3915,8 +3915,8 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
                                    file) < 0) {
         if (virCgroupDenyDevice(priv->cgroup,
                                 'b',
-                                major(sb.st_rdev),
-                                minor(sb.st_rdev),
+                                gnu_dev_major(sb.st_rdev),
+                                gnu_dev_minor(sb.st_rdev),
                                 perms) < 0)
             VIR_WARN("cannot deny device %s for domain %s",
                      src, vm->def->name);
@@ -4152,8 +4152,8 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
 
     if (virCgroupAllowDevice(priv->cgroup,
                              'b',
-                             major(sb.st_rdev),
-                             minor(sb.st_rdev),
+                             gnu_dev_major(sb.st_rdev),
+                             gnu_dev_minor(sb.st_rdev),
                              VIR_CGROUP_DEVICE_RWM) < 0)
         goto cleanup;
 
@@ -4165,8 +4165,8 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
                                    def->source.caps.u.storage.block) < 0) {
         if (virCgroupDenyDevice(priv->cgroup,
                                 'b',
-                                major(sb.st_rdev),
-                                minor(sb.st_rdev),
+                                gnu_dev_major(sb.st_rdev),
+                                gnu_dev_minor(sb.st_rdev),
                                 VIR_CGROUP_DEVICE_RWM) < 0)
             VIR_WARN("cannot deny device %s for domain %s",
                      def->source.caps.u.storage.block, vm->def->name);
@@ -4221,8 +4221,8 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
 
     if (virCgroupAllowDevice(priv->cgroup,
                              'c',
-                             major(sb.st_rdev),
-                             minor(sb.st_rdev),
+                             gnu_dev_major(sb.st_rdev),
+                             gnu_dev_minor(sb.st_rdev),
                              VIR_CGROUP_DEVICE_RWM) < 0)
         goto cleanup;
 
@@ -4237,8 +4237,8 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
                                    def->source.caps.u.misc.chardev) < 0) {
         if (virCgroupDenyDevice(priv->cgroup,
                                 'c',
-                                major(sb.st_rdev),
-                                minor(sb.st_rdev),
+                                gnu_dev_major(sb.st_rdev),
+                                gnu_dev_minor(sb.st_rdev),
                                 VIR_CGROUP_DEVICE_RWM) < 0)
             VIR_WARN("cannot deny device %s for domain %s",
                      def->source.caps.u.storage.block, vm->def->name);
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index f2477d5..f4f6a01 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -765,7 +765,7 @@ virCgroupGetBlockDevString(const char *path)
 
     /* Automatically append space after the string since all callers
      * use it anyway */
-    if (virAsprintf(&ret, "%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)) < 0)
+    if (virAsprintf(&ret, "%d:%d ", gnu_dev_major(sb.st_rdev), gnu_dev_minor(sb.st_rdev)) < 0)
         return NULL;
 
     return ret;
@@ -2941,8 +2941,8 @@ virCgroupAllowDevicePath(virCgroupPtr group,
 
     return virCgroupAllowDevice(group,
                                 S_ISCHR(sb.st_mode) ? 'c' : 'b',
-                                major(sb.st_rdev),
-                                minor(sb.st_rdev),
+                                gnu_dev_major(sb.st_rdev),
+                                gnu_dev_minor(sb.st_rdev),
                                 perms);
 }
 
@@ -3032,8 +3032,8 @@ virCgroupDenyDevicePath(virCgroupPtr group,
 
     return virCgroupDenyDevice(group,
                                S_ISCHR(sb.st_mode) ? 'c' : 'b',
-                               major(sb.st_rdev),
-                               minor(sb.st_rdev),
+                               gnu_dev_major(sb.st_rdev),
+                               gnu_dev_minor(sb.st_rdev),
                                perms);
 }
 
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 170dd59..b0770bc 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1616,7 +1616,7 @@ virIsDevMapperDevice(const char *dev_name)
 
     if (!stat(dev_name, &buf) &&
         S_ISBLK(buf.st_mode) &&
-        dm_is_dm_major(major(buf.st_rdev)))
+        dm_is_dm_major(gnu_dev_major(buf.st_rdev)))
             return true;
 
     return false;
@@ -1664,9 +1664,9 @@ virGetDeviceID(const char *path, int *maj, int *min)
         return -EINVAL;
 
     if (maj)
-        *maj = major(sb.st_rdev);
+        *maj = gnu_dev_major(sb.st_rdev);
     if (min)
-        *min = minor(sb.st_rdev);
+        *min = gnu_dev_minor(sb.st_rdev);
 
     return 0;
 }
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index ce6fd46..8f69047 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -562,11 +562,11 @@ int __lxstat(int ver, const char *path, struct stat *sb)
         free(newpath);
     } else if (STRPREFIX(path, fakedevicedir0)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(8, 0);
+        sb->st_rdev = gnu_dev_makedev(8, 0);
         return 0;
     } else if (STRPREFIX(path, fakedevicedir1)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(9, 0);
+        sb->st_rdev = gnu_dev_makedev(9, 0);
         return 0;
     } else {
         ret = real___lxstat(ver, path, sb);
@@ -593,11 +593,11 @@ int lstat(const char *path, struct stat *sb)
         free(newpath);
     } else if (STRPREFIX(path, fakedevicedir0)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(8, 0);
+        sb->st_rdev = gnu_dev_makedev(8, 0);
         return 0;
     } else if (STRPREFIX(path, fakedevicedir1)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(9, 0);
+        sb->st_rdev = gnu_dev_makedev(9, 0);
         return 0;
     } else {
         ret = real_lstat(path, sb);
@@ -624,11 +624,11 @@ int __xstat(int ver, const char *path, struct stat *sb)
         free(newpath);
     } else if (STRPREFIX(path, fakedevicedir0)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(8, 0);
+        sb->st_rdev = gnu_dev_makedev(8, 0);
         return 0;
     } else if (STRPREFIX(path, fakedevicedir1)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(9, 0);
+        sb->st_rdev = gnu_dev_makedev(9, 0);
         return 0;
     } else {
         ret = real___xstat(ver, path, sb);
@@ -661,11 +661,11 @@ int stat(const char *path, struct stat *sb)
         }
     } else if (STRPREFIX(path, fakedevicedir0)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(8, 0);
+        sb->st_rdev = gnu_dev_makedev(8, 0);
         return 0;
     } else if (STRPREFIX(path, fakedevicedir1)) {
         sb->st_mode = S_IFBLK;
-        sb->st_rdev = makedev(9, 0);
+        sb->st_rdev = gnu_dev_makedev(9, 0);
         return 0;
     } else {
         if (!(newpath = strdup(path)))
-- 
2.8.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



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