Blame SOURCES/0014-RHEL-7-Remove-9p-APIs-from-RHEL-RHBZ-921710.patch

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