mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0076-RHEL-8-Remove-9p-APIs-from-RHEL-RHBZ-921710.patch

498672
From 683153015b95a7b6d4979d48736c80e366986c72 Mon Sep 17 00:00:00 2001
d0ea73
From: "Richard W.M. Jones" <rjones@redhat.com>
d0ea73
Date: Thu, 18 Jul 2013 18:31:53 +0100
d0ea73
Subject: [PATCH] RHEL 8: Remove 9p APIs from RHEL (RHBZ#921710).
d0ea73
d0ea73
---
d0ea73
 Makefile.am               |   2 +-
d0ea73
 daemon/9p.c               | 224 --------------------------------------
d0ea73
 daemon/Makefile.am        |   1 -
d0ea73
 docs/C_SOURCE_FILES       |   1 -
d0ea73
 generator/actions_core.ml |  21 ----
d0ea73
 generator/proc_nr.ml      |   2 -
d0ea73
 gobject/Makefile.inc      |   2 -
d0ea73
 po/POTFILES               |   2 -
d0ea73
 8 files changed, 1 insertion(+), 254 deletions(-)
d0ea73
 delete mode 100644 daemon/9p.c
d0ea73
d0ea73
diff --git a/Makefile.am b/Makefile.am
10436e
index 0067d7b7b..e9351eadc 100644
d0ea73
--- a/Makefile.am
d0ea73
+++ b/Makefile.am
d0ea73
@@ -78,7 +78,7 @@ SUBDIRS += tests/xfs
d0ea73
 SUBDIRS += tests/charsets
d0ea73
 SUBDIRS += tests/xml
d0ea73
 SUBDIRS += tests/mount-local
d0ea73
-SUBDIRS += tests/9p
d0ea73
+#SUBDIRS += tests/9p
d0ea73
 SUBDIRS += tests/rsync
d0ea73
 SUBDIRS += tests/bigdirs
d0ea73
 SUBDIRS += tests/disk-labels
d0ea73
diff --git a/daemon/9p.c b/daemon/9p.c
d0ea73
deleted file mode 100644
d0ea73
index 55644249d..000000000
d0ea73
--- a/daemon/9p.c
d0ea73
+++ /dev/null
d0ea73
@@ -1,224 +0,0 @@
d0ea73
-/* libguestfs - the guestfsd daemon
d0ea73
- * Copyright (C) 2011 Red Hat Inc.
d0ea73
- *
d0ea73
- * This program is free software; you can redistribute it and/or modify
d0ea73
- * it under the terms of the GNU General Public License as published by
d0ea73
- * the Free Software Foundation; either version 2 of the License, or
d0ea73
- * (at your option) any later version.
d0ea73
- *
d0ea73
- * This program is distributed in the hope that it will be useful,
d0ea73
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
d0ea73
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d0ea73
- * GNU General Public License for more details.
d0ea73
- *
d0ea73
- * You should have received a copy of the GNU General Public License
d0ea73
- * along with this program; if not, write to the Free Software
d0ea73
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d0ea73
- */
d0ea73
-
d0ea73
-#include <config.h>
d0ea73
-
d0ea73
-#include <stdio.h>
d0ea73
-#include <stdlib.h>
d0ea73
-#include <string.h>
d0ea73
-#include <unistd.h>
d0ea73
-#include <limits.h>
d0ea73
-#include <errno.h>
d0ea73
-#include <sys/types.h>
d0ea73
-#include <sys/stat.h>
d0ea73
-#include <dirent.h>
d0ea73
-#include <fcntl.h>
d0ea73
-
d0ea73
-#include "daemon.h"
d0ea73
-#include "actions.h"
d0ea73
-
d0ea73
-#define BUS_PATH "/sys/bus/virtio/drivers/9pnet_virtio"
d0ea73
-
d0ea73
-static char *read_whole_file (const char *filename);
d0ea73
-
d0ea73
-/* https://bugzilla.redhat.com/show_bug.cgi?id=714981#c1 */
d0ea73
-char **
d0ea73
-do_list_9p (void)
d0ea73
-{
d0ea73
-  CLEANUP_FREE_STRINGSBUF DECLARE_STRINGSBUF (r);
d0ea73
-
d0ea73
-  DIR *dir;
d0ea73
-
d0ea73
-  dir = opendir (BUS_PATH);
d0ea73
-  if (!dir) {
d0ea73
-    perror ("opendir: " BUS_PATH);
d0ea73
-    if (errno != ENOENT) {
d0ea73
-      reply_with_perror ("opendir: " BUS_PATH);
d0ea73
-      return NULL;
d0ea73
-    }
d0ea73
-
d0ea73
-    /* If this directory doesn't exist, it probably means that
d0ea73
-     * the virtio driver isn't loaded.  Don't return an error
d0ea73
-     * in this case, but return an empty list.
d0ea73
-     */
d0ea73
-    if (end_stringsbuf (&r) == -1)
d0ea73
-      return NULL;
d0ea73
-
d0ea73
-    return take_stringsbuf (&r);
d0ea73
-  }
d0ea73
-
d0ea73
-  while (1) {
d0ea73
-    struct dirent *d;
d0ea73
-
d0ea73
-    errno = 0;
d0ea73
-    d = readdir (dir);
d0ea73
-    if (d == NULL) break;
d0ea73
-
d0ea73
-    if (STRPREFIX (d->d_name, "virtio")) {
d0ea73
-      CLEANUP_FREE char *mount_tag_path = NULL;
d0ea73
-      if (asprintf (&mount_tag_path, BUS_PATH "/%s/mount_tag",
d0ea73
-                    d->d_name) == -1) {
d0ea73
-        reply_with_perror ("asprintf");
d0ea73
-        closedir (dir);
d0ea73
-        return NULL;
d0ea73
-      }
d0ea73
-
d0ea73
-      /* A bit unclear, but it looks like the virtio transport allows
d0ea73
-       * the mount tag length to be unlimited (or up to 65536 bytes).
d0ea73
-       * See: linux/include/linux/virtio_9p.h
d0ea73
-       */
d0ea73
-      CLEANUP_FREE char *mount_tag = read_whole_file (mount_tag_path);
d0ea73
-      if (mount_tag == 0)
d0ea73
-        continue;
d0ea73
-
d0ea73
-      if (add_string (&r, mount_tag) == -1) {
d0ea73
-        closedir (dir);
d0ea73
-        return NULL;
d0ea73
-      }
d0ea73
-    }
d0ea73
-  }
d0ea73
-
d0ea73
-  /* Check readdir didn't fail */
d0ea73
-  if (errno != 0) {
d0ea73
-    reply_with_perror ("readdir: /sys/block");
d0ea73
-    closedir (dir);
d0ea73
-    return NULL;
d0ea73
-  }
d0ea73
-
d0ea73
-  /* Close the directory handle */
d0ea73
-  if (closedir (dir) == -1) {
d0ea73
-    reply_with_perror ("closedir: /sys/block");
d0ea73
-    return NULL;
d0ea73
-  }
d0ea73
-
d0ea73
-  /* Sort the tags. */
d0ea73
-  if (r.size > 0)
d0ea73
-    sort_strings (r.argv, r.size);
d0ea73
-
d0ea73
-  /* NULL terminate the list */
d0ea73
-  if (end_stringsbuf (&r) == -1)
d0ea73
-    return NULL;
d0ea73
-
d0ea73
-  return take_stringsbuf (&r);
d0ea73
-}
d0ea73
-
d0ea73
-/* Read whole file into dynamically allocated array.  If there is an
d0ea73
- * error, DON'T call reply_with_perror, just return NULL.  Returns a
d0ea73
- * \0-terminated string.
d0ea73
- */
d0ea73
-static char *
d0ea73
-read_whole_file (const char *filename)
d0ea73
-{
d0ea73
-  char *r = NULL;
d0ea73
-  size_t alloc = 0, size = 0;
d0ea73
-  int fd;
d0ea73
-
d0ea73
-  fd = open (filename, O_RDONLY|O_CLOEXEC);
d0ea73
-  if (fd == -1) {
d0ea73
-    perror (filename);
d0ea73
-    return NULL;
d0ea73
-  }
d0ea73
-
d0ea73
-  while (1) {
d0ea73
-    alloc += 256;
d0ea73
-    char *r2 = realloc (r, alloc);
d0ea73
-    if (r2 == NULL) {
d0ea73
-      perror ("realloc");
d0ea73
-      free (r);
d0ea73
-      close (fd);
d0ea73
-      return NULL;
d0ea73
-    }
d0ea73
-    r = r2;
d0ea73
-
d0ea73
-    /* The '- 1' in the size calculation ensures there is space below
d0ea73
-     * to add \0 to the end of the input.
d0ea73
-     */
d0ea73
-    ssize_t n = read (fd, r + size, alloc - size - 1);
d0ea73
-    if (n == -1) {
d0ea73
-      fprintf (stderr, "read: %s: %m\n", filename);
d0ea73
-      free (r);
d0ea73
-      close (fd);
d0ea73
-      return NULL;
d0ea73
-    }
d0ea73
-    if (n == 0)
d0ea73
-      break;
d0ea73
-    size += n;
d0ea73
-  }
d0ea73
-
d0ea73
-  if (close (fd) == -1) {
d0ea73
-    fprintf (stderr, "close: %s: %m\n", filename);
d0ea73
-    free (r);
d0ea73
-    return NULL;
d0ea73
-  }
d0ea73
-
d0ea73
-  r[size] = '\0';
d0ea73
-
d0ea73
-  return r;
d0ea73
-}
d0ea73
-
d0ea73
-/* Takes optional arguments, consult optargs_bitmask. */
d0ea73
-int
d0ea73
-do_mount_9p (const char *mount_tag, const char *mountpoint, const char *options)
d0ea73
-{
d0ea73
-  CLEANUP_FREE char *mp = NULL, *opts = NULL, *err = NULL;
d0ea73
-  struct stat statbuf;
d0ea73
-  int r;
d0ea73
-
d0ea73
-  ABS_PATH (mountpoint, 0, return -1);
d0ea73
-
d0ea73
-  mp = sysroot_path (mountpoint);
d0ea73
-  if (!mp) {
d0ea73
-    reply_with_perror ("malloc");
d0ea73
-    return -1;
d0ea73
-  }
d0ea73
-
d0ea73
-  /* Check the mountpoint exists and is a directory. */
d0ea73
-  if (stat (mp, &statbuf) == -1) {
d0ea73
-    reply_with_perror ("%s", mountpoint);
d0ea73
-    return -1;
d0ea73
-  }
d0ea73
-  if (!S_ISDIR (statbuf.st_mode)) {
d0ea73
-    reply_with_perror ("%s: mount point is not a directory", mountpoint);
d0ea73
-    return -1;
d0ea73
-  }
d0ea73
-
d0ea73
-  /* Add trans=virtio to the options. */
d0ea73
-  if ((optargs_bitmask & GUESTFS_MOUNT_9P_OPTIONS_BITMASK) &&
d0ea73
-      STRNEQ (options, "")) {
d0ea73
-    if (asprintf (&opts, "trans=virtio,%s", options) == -1) {
d0ea73
-      reply_with_perror ("asprintf");
d0ea73
-      return -1;
d0ea73
-    }
d0ea73
-  }
d0ea73
-  else {
d0ea73
-    opts = strdup ("trans=virtio");
d0ea73
-    if (opts == NULL) {
d0ea73
-      reply_with_perror ("strdup");
d0ea73
-      return -1;
d0ea73
-    }
d0ea73
-  }
d0ea73
-
d0ea73
-  r = command (NULL, &err,
d0ea73
-               "mount", "-o", opts, "-t", "9p", mount_tag, mp, NULL);
d0ea73
-  if (r == -1) {
d0ea73
-    reply_with_error ("%s on %s: %s", mount_tag, mountpoint, err);
d0ea73
-    return -1;
d0ea73
-  }
d0ea73
-
d0ea73
-  return 0;
d0ea73
-}
d0ea73
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
10436e
index 5d1c222db..a9b40be25 100644
d0ea73
--- a/daemon/Makefile.am
d0ea73
+++ b/daemon/Makefile.am
d0ea73
@@ -76,7 +76,6 @@ guestfsd_SOURCES = \
d0ea73
 	../common/protocol/guestfs_protocol.h \
d0ea73
 	../common/utils/cleanups.h \
d0ea73
 	../common/utils/guestfs-utils.h \
d0ea73
-	9p.c \
d0ea73
 	acl.c \
d0ea73
 	actions.h \
d0ea73
 	available.c \
d0ea73
diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES
10436e
index 7f1c60b30..f45e7124d 100644
d0ea73
--- a/docs/C_SOURCE_FILES
d0ea73
+++ b/docs/C_SOURCE_FILES
10436e
@@ -71,7 +71,6 @@ common/windows/windows.h
d0ea73
 customize/crypt-c.c
d0ea73
 customize/dummy.c
d0ea73
 customize/perl_edit-c.c
d0ea73
-daemon/9p.c
d0ea73
 daemon/acl.c
d0ea73
 daemon/actions.h
d0ea73
 daemon/augeas.c
d0ea73
diff --git a/generator/actions_core.ml b/generator/actions_core.ml
10436e
index deda483a9..f466600df 100644
d0ea73
--- a/generator/actions_core.ml
d0ea73
+++ b/generator/actions_core.ml
10436e
@@ -6167,27 +6167,6 @@ This returns true iff the device exists and contains all zero bytes.
d0ea73
 
d0ea73
 Note that for large devices this can take a long time to run." };
d0ea73
 
d0ea73
-  { defaults with
d0ea73
-    name = "list_9p"; added = (1, 11, 12);
d0ea73
-    style = RStringList (RPlainString, "mounttags"), [], [];
d0ea73
-    shortdesc = "list 9p filesystems";
d0ea73
-    longdesc = "\
d0ea73
-List all 9p filesystems attached to the guest.  A list of
d0ea73
-mount tags is returned." };
d0ea73
-
d0ea73
-  { defaults with
d0ea73
-    name = "mount_9p"; added = (1, 11, 12);
d0ea73
-    style = RErr, [String (PlainString, "mounttag"); String (PlainString, "mountpoint")], [OString "options"];
d0ea73
-    camel_name = "Mount9P";
d0ea73
-    shortdesc = "mount 9p filesystem";
d0ea73
-    longdesc = "\
d0ea73
-Mount the virtio-9p filesystem with the tag C<mounttag> on the
d0ea73
-directory C<mountpoint>.
d0ea73
-
d0ea73
-If required, C<trans=virtio> will be automatically added to the options.
d0ea73
-Any other options required can be passed in the optional C<options>
d0ea73
-parameter." };
d0ea73
-
d0ea73
   { defaults with
d0ea73
     name = "list_dm_devices"; added = (1, 11, 15);
d0ea73
     style = RStringList (RDevice, "devices"), [], [];
d0ea73
diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml
10436e
index 11a557076..1ef5ba0b7 100644
d0ea73
--- a/generator/proc_nr.ml
d0ea73
+++ b/generator/proc_nr.ml
d0ea73
@@ -295,8 +295,6 @@ let proc_nr = [
d0ea73
 282, "internal_autosync";
d0ea73
 283, "is_zero";
d0ea73
 284, "is_zero_device";
d0ea73
-285, "list_9p";
d0ea73
-286, "mount_9p";
d0ea73
 287, "list_dm_devices";
d0ea73
 288, "ntfsresize";
d0ea73
 289, "btrfs_filesystem_resize";
d0ea73
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
10436e
index 067f861a9..7afe83c59 100644
d0ea73
--- a/gobject/Makefile.inc
d0ea73
+++ b/gobject/Makefile.inc
d0ea73
@@ -93,7 +93,6 @@ guestfs_gobject_headers= \
d0ea73
   include/guestfs-gobject/optargs-mksquashfs.h \
d0ea73
   include/guestfs-gobject/optargs-mkswap.h \
d0ea73
   include/guestfs-gobject/optargs-mktemp.h \
d0ea73
-  include/guestfs-gobject/optargs-mount_9p.h \
d0ea73
   include/guestfs-gobject/optargs-mount_local.h \
d0ea73
   include/guestfs-gobject/optargs-ntfsclone_out.h \
d0ea73
   include/guestfs-gobject/optargs-ntfsfix.h \
d0ea73
@@ -186,7 +185,6 @@ guestfs_gobject_sources= \
d0ea73
   src/optargs-mksquashfs.c \
d0ea73
   src/optargs-mkswap.c \
d0ea73
   src/optargs-mktemp.c \
d0ea73
-  src/optargs-mount_9p.c \
d0ea73
   src/optargs-mount_local.c \
d0ea73
   src/optargs-ntfsclone_out.c \
d0ea73
   src/optargs-ntfsfix.c \
d0ea73
diff --git a/po/POTFILES b/po/POTFILES
10436e
index 79f4b8c56..b99333d0d 100644
d0ea73
--- a/po/POTFILES
d0ea73
+++ b/po/POTFILES
d0ea73
@@ -58,7 +58,6 @@ customize/crypt-c.c
d0ea73
 customize/dummy.c
d0ea73
 customize/perl_edit-c.c
d0ea73
 customize/test-password.pl
d0ea73
-daemon/9p.c
d0ea73
 daemon/acl.c
d0ea73
 daemon/augeas.c
d0ea73
 daemon/available.c
10436e
@@ -291,7 +290,6 @@ gobject/src/optargs-mkfs_btrfs.c
d0ea73
 gobject/src/optargs-mksquashfs.c
d0ea73
 gobject/src/optargs-mkswap.c
d0ea73
 gobject/src/optargs-mktemp.c
d0ea73
-gobject/src/optargs-mount_9p.c
d0ea73
 gobject/src/optargs-mount_local.c
d0ea73
 gobject/src/optargs-ntfsclone_out.c
d0ea73
 gobject/src/optargs-ntfsfix.c
d0ea73
-- 
498672
2.18.4
d0ea73