mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

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

e76f14
From 46238a80e68fcb4c8b65b6f4aab050aa0316a8e7 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
---
022f11
 Makefile.am          |   2 +-
e76f14
 daemon/9p.c          | 221 ---------------------------------------------------
022f11
 daemon/Makefile.am   |   1 -
022f11
 generator/actions.ml |  23 ------
022f11
 gobject/Makefile.inc |   2 -
022f11
 po/POTFILES          |   2 -
e76f14
 6 files changed, 1 insertion(+), 250 deletions(-)
022f11
 delete mode 100644 daemon/9p.c
022f11
022f11
diff --git a/Makefile.am b/Makefile.am
e76f14
index 524e397..c77fc34 100644
022f11
--- a/Makefile.am
022f11
+++ b/Makefile.am
e76f14
@@ -71,7 +71,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
e76f14
index a9e36d1..0000000
022f11
--- a/daemon/9p.c
022f11
+++ /dev/null
e76f14
@@ -1,221 +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
-GUESTFSD_EXT_CMD(str_mount, mount);
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")) {
022f11
-      char mount_tag_path[256];
022f11
-      snprintf (mount_tag_path, sizeof mount_tag_path,
022f11
-                BUS_PATH "/%s/mount_tag", d->d_name);
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
-
022f11
-  ABS_PATH (mountpoint, , 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,
022f11
-               str_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
e76f14
index 997d89f..20a6289 100644
022f11
--- a/daemon/Makefile.am
022f11
+++ b/daemon/Makefile.am
e76f14
@@ -83,7 +83,6 @@ endif
e76f14
 # https://rwmj.wordpress.com/2015/09/30/make-and-queuing-theory/#content
022f11
 guestfsd_SOURCES = \
e76f14
 	stubs.c \
022f11
-	9p.c \
022f11
 	acl.c \
022f11
 	actions.h \
022f11
 	available.c \
022f11
diff --git a/generator/actions.ml b/generator/actions.ml
e76f14
index 304fd80..9248ded 100644
022f11
--- a/generator/actions.ml
022f11
+++ b/generator/actions.ml
e76f14
@@ -9359,29 +9359,6 @@ This returns true iff the device exists and contains all zero bytes.
022f11
 Note that for large devices this can take a long time to run." };
022f11
 
022f11
   { defaults with
e76f14
-    name = "list_9p"; added = (1, 11, 12);
022f11
-    style = RStringList "mounttags", [], [];
022f11
-    proc_nr = Some 285;
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);
022f11
-    style = RErr, [String "mounttag"; String "mountpoint"], [OString "options"];
022f11
-    proc_nr = Some 286;
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
-
022f11
-  { defaults with
e76f14
     name = "list_dm_devices"; added = (1, 11, 15);
022f11
     style = RStringList "devices", [], [];
022f11
     proc_nr = Some 287;
022f11
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
e76f14
index 3bb8041..20c98ff 100644
022f11
--- a/gobject/Makefile.inc
022f11
+++ b/gobject/Makefile.inc
e76f14
@@ -87,7 +87,6 @@ guestfs_gobject_headers= \
0d20ef
   include/guestfs-gobject/optargs-mkfs_btrfs.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 \
e76f14
@@ -173,7 +172,6 @@ guestfs_gobject_sources= \
0d20ef
   src/optargs-mkfs_btrfs.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
e76f14
index d025941..d4058ac 100644
022f11
--- a/po/POTFILES
022f11
+++ b/po/POTFILES
0d20ef
@@ -14,7 +14,6 @@ cat/ls.c
0d20ef
 cat/visit.c
0d20ef
 customize/crypt-c.c
0d20ef
 customize/perl_edit-c.c
022f11
-daemon/9p.c
022f11
 daemon/acl.c
022f11
 daemon/augeas.c
022f11
 daemon/available.c
e76f14
@@ -213,7 +212,6 @@ gobject/src/optargs-mkfs.c
022f11
 gobject/src/optargs-mkfs_btrfs.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
-- 
aa0300
2.7.4
022f11