summaryrefslogtreecommitdiffstats
path: root/qemu/fsdev
diff options
context:
space:
mode:
authorDon Dugger <n0ano@n0ano.com>2016-06-03 03:33:22 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-03 03:33:23 +0000
commitda27230f80795d0028333713f036d44c53cb0e68 (patch)
treeb3d379eaf000adf72b36cb01cdf4d79c3e3f064c /qemu/fsdev
parent0e68cb048bb8aadb14675f5d4286d8ab2fc35449 (diff)
parent437fd90c0250dee670290f9b714253671a990160 (diff)
Merge "These changes are the raw update to qemu-2.6."
Diffstat (limited to 'qemu/fsdev')
-rw-r--r--qemu/fsdev/9p-iov-marshal.c (renamed from qemu/fsdev/virtio-9p-marshal.c)183
-rw-r--r--qemu/fsdev/9p-iov-marshal.h18
-rw-r--r--qemu/fsdev/9p-marshal.c51
-rw-r--r--qemu/fsdev/9p-marshal.h (renamed from qemu/fsdev/virtio-9p-marshal.h)12
-rw-r--r--qemu/fsdev/Makefile.objs2
-rw-r--r--qemu/fsdev/file-op-9p.h3
-rw-r--r--qemu/fsdev/qemu-fsdev-dummy.c3
-rw-r--r--qemu/fsdev/qemu-fsdev-opts.c3
-rw-r--r--qemu/fsdev/qemu-fsdev.c11
-rw-r--r--qemu/fsdev/virtfs-proxy-helper.c27
-rw-r--r--qemu/fsdev/virtfs-proxy-helper.texi6
11 files changed, 185 insertions, 134 deletions
diff --git a/qemu/fsdev/virtio-9p-marshal.c b/qemu/fsdev/9p-iov-marshal.c
index 20f308b76..fb40bdf0d 100644
--- a/qemu/fsdev/virtio-9p-marshal.c
+++ b/qemu/fsdev/9p-iov-marshal.c
@@ -1,5 +1,5 @@
/*
- * Virtio 9p backend
+ * 9p backend
*
* Copyright IBM, Corp. 2010
*
@@ -11,52 +11,15 @@
*
*/
+#include "qemu/osdep.h"
#include <glib.h>
#include <glib/gprintf.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <sys/time.h>
#include <utime.h>
#include <sys/uio.h>
-#include <string.h>
-#include <stdint.h>
-#include <errno.h>
-#include "qemu/compiler.h"
-#include "virtio-9p-marshal.h"
+#include "9p-iov-marshal.h"
#include "qemu/bswap.h"
-void v9fs_string_free(V9fsString *str)
-{
- g_free(str->data);
- str->data = NULL;
- str->size = 0;
-}
-
-void v9fs_string_null(V9fsString *str)
-{
- v9fs_string_free(str);
-}
-
-void GCC_FMT_ATTR(2, 3)
-v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
-{
- va_list ap;
-
- v9fs_string_free(str);
-
- va_start(ap, fmt);
- str->size = g_vasprintf(&str->data, fmt, ap);
- va_end(ap);
-}
-
-void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
-{
- v9fs_string_free(lhs);
- v9fs_string_sprintf(lhs, "%s", rhs->data);
-}
-
-
static ssize_t v9fs_packunpack(void *addr, struct iovec *sg, int sg_count,
size_t offset, size_t size, int pack)
{
@@ -108,15 +71,13 @@ ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
}
-ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
- int bswap, const char *fmt, ...)
+ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int out_num, size_t offset,
+ int bswap, const char *fmt, va_list ap)
{
int i;
- va_list ap;
ssize_t copied = 0;
size_t old_offset = offset;
- va_start(ap, fmt);
for (i = 0; fmt[i]; i++) {
switch (fmt[i]) {
case 'b': {
@@ -159,8 +120,8 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
}
case 's': {
V9fsString *str = va_arg(ap, V9fsString *);
- copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
- "w", &str->size);
+ copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+ "w", &str->size);
if (copied > 0) {
offset += copied;
str->data = g_malloc(str->size + 1);
@@ -176,56 +137,70 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
}
case 'Q': {
V9fsQID *qidp = va_arg(ap, V9fsQID *);
- copied = v9fs_unmarshal(out_sg, out_num, offset, bswap, "bdq",
- &qidp->type, &qidp->version, &qidp->path);
+ copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+ "bdq", &qidp->type, &qidp->version,
+ &qidp->path);
break;
}
case 'S': {
V9fsStat *statp = va_arg(ap, V9fsStat *);
- copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
- "wwdQdddqsssssddd",
- &statp->size, &statp->type, &statp->dev,
- &statp->qid, &statp->mode, &statp->atime,
- &statp->mtime, &statp->length,
- &statp->name, &statp->uid, &statp->gid,
- &statp->muid, &statp->extension,
- &statp->n_uid, &statp->n_gid,
- &statp->n_muid);
+ copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+ "wwdQdddqsssssddd",
+ &statp->size, &statp->type,
+ &statp->dev, &statp->qid,
+ &statp->mode, &statp->atime,
+ &statp->mtime, &statp->length,
+ &statp->name, &statp->uid,
+ &statp->gid, &statp->muid,
+ &statp->extension,
+ &statp->n_uid, &statp->n_gid,
+ &statp->n_muid);
break;
}
case 'I': {
V9fsIattr *iattr = va_arg(ap, V9fsIattr *);
- copied = v9fs_unmarshal(out_sg, out_num, offset, bswap,
- "ddddqqqqq",
- &iattr->valid, &iattr->mode,
- &iattr->uid, &iattr->gid, &iattr->size,
- &iattr->atime_sec, &iattr->atime_nsec,
- &iattr->mtime_sec, &iattr->mtime_nsec);
+ copied = v9fs_iov_unmarshal(out_sg, out_num, offset, bswap,
+ "ddddqqqqq",
+ &iattr->valid, &iattr->mode,
+ &iattr->uid, &iattr->gid,
+ &iattr->size, &iattr->atime_sec,
+ &iattr->atime_nsec,
+ &iattr->mtime_sec,
+ &iattr->mtime_nsec);
break;
}
default:
break;
}
if (copied < 0) {
- va_end(ap);
return copied;
}
offset += copied;
}
- va_end(ap);
return offset - old_offset;
}
-ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
- int bswap, const char *fmt, ...)
+ssize_t v9fs_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
+ int bswap, const char *fmt, ...)
{
- int i;
+ ssize_t ret;
va_list ap;
+
+ va_start(ap, fmt);
+ ret = v9fs_iov_vunmarshal(out_sg, out_num, offset, bswap, fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
+
+ssize_t v9fs_iov_vmarshal(struct iovec *in_sg, int in_num, size_t offset,
+ int bswap, const char *fmt, va_list ap)
+{
+ int i;
ssize_t copied = 0;
size_t old_offset = offset;
- va_start(ap, fmt);
for (i = 0; fmt[i]; i++) {
switch (fmt[i]) {
case 'b': {
@@ -265,8 +240,8 @@ ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
}
case 's': {
V9fsString *str = va_arg(ap, V9fsString *);
- copied = v9fs_marshal(in_sg, in_num, offset, bswap,
- "w", str->size);
+ copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap,
+ "w", str->size);
if (copied > 0) {
offset += copied;
copied = v9fs_pack(in_sg, in_num, offset, str->data, str->size);
@@ -275,49 +250,65 @@ ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
}
case 'Q': {
V9fsQID *qidp = va_arg(ap, V9fsQID *);
- copied = v9fs_marshal(in_sg, in_num, offset, bswap, "bdq",
- qidp->type, qidp->version, qidp->path);
+ copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap, "bdq",
+ qidp->type, qidp->version,
+ qidp->path);
break;
}
case 'S': {
V9fsStat *statp = va_arg(ap, V9fsStat *);
- copied = v9fs_marshal(in_sg, in_num, offset, bswap,
- "wwdQdddqsssssddd",
- statp->size, statp->type, statp->dev,
- &statp->qid, statp->mode, statp->atime,
- statp->mtime, statp->length, &statp->name,
- &statp->uid, &statp->gid, &statp->muid,
- &statp->extension, statp->n_uid,
- statp->n_gid, statp->n_muid);
+ copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap,
+ "wwdQdddqsssssddd",
+ statp->size, statp->type, statp->dev,
+ &statp->qid, statp->mode, statp->atime,
+ statp->mtime, statp->length,
+ &statp->name,
+ &statp->uid, &statp->gid, &statp->muid,
+ &statp->extension, statp->n_uid,
+ statp->n_gid, statp->n_muid);
break;
}
case 'A': {
V9fsStatDotl *statp = va_arg(ap, V9fsStatDotl *);
- copied = v9fs_marshal(in_sg, in_num, offset, bswap,
- "qQdddqqqqqqqqqqqqqqq",
- statp->st_result_mask,
- &statp->qid, statp->st_mode,
- statp->st_uid, statp->st_gid,
- statp->st_nlink, statp->st_rdev,
- statp->st_size, statp->st_blksize,
- statp->st_blocks, statp->st_atime_sec,
- statp->st_atime_nsec, statp->st_mtime_sec,
- statp->st_mtime_nsec, statp->st_ctime_sec,
- statp->st_ctime_nsec, statp->st_btime_sec,
- statp->st_btime_nsec, statp->st_gen,
- statp->st_data_version);
+ copied = v9fs_iov_marshal(in_sg, in_num, offset, bswap,
+ "qQdddqqqqqqqqqqqqqqq",
+ statp->st_result_mask,
+ &statp->qid, statp->st_mode,
+ statp->st_uid, statp->st_gid,
+ statp->st_nlink, statp->st_rdev,
+ statp->st_size, statp->st_blksize,
+ statp->st_blocks, statp->st_atime_sec,
+ statp->st_atime_nsec,
+ statp->st_mtime_sec,
+ statp->st_mtime_nsec,
+ statp->st_ctime_sec,
+ statp->st_ctime_nsec,
+ statp->st_btime_sec,
+ statp->st_btime_nsec, statp->st_gen,
+ statp->st_data_version);
break;
}
default:
break;
}
if (copied < 0) {
- va_end(ap);
return copied;
}
offset += copied;
}
- va_end(ap);
return offset - old_offset;
}
+
+ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
+ int bswap, const char *fmt, ...)
+{
+ ssize_t ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = v9fs_iov_vmarshal(in_sg, in_num, offset, bswap, fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
diff --git a/qemu/fsdev/9p-iov-marshal.h b/qemu/fsdev/9p-iov-marshal.h
new file mode 100644
index 000000000..6bccbfb41
--- /dev/null
+++ b/qemu/fsdev/9p-iov-marshal.h
@@ -0,0 +1,18 @@
+#ifndef _QEMU_9P_IOV_MARSHAL_H
+#define _QEMU_9P_IOV_MARSHAL_H
+
+#include "9p-marshal.h"
+
+
+ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
+ const void *src, size_t size);
+ssize_t v9fs_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
+ int bswap, const char *fmt, ...);
+ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
+ int bswap, const char *fmt, ...);
+
+ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int out_num, size_t offset,
+ int bswap, const char *fmt, va_list ap);
+ssize_t v9fs_iov_vmarshal(struct iovec *in_sg, int in_num, size_t offset,
+ int bswap, const char *fmt, va_list ap);
+#endif
diff --git a/qemu/fsdev/9p-marshal.c b/qemu/fsdev/9p-marshal.c
new file mode 100644
index 000000000..183d3667c
--- /dev/null
+++ b/qemu/fsdev/9p-marshal.c
@@ -0,0 +1,51 @@
+/*
+ * 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <dirent.h>
+#include <utime.h>
+#include <sys/uio.h>
+
+#include "9p-marshal.h"
+
+void v9fs_string_free(V9fsString *str)
+{
+ g_free(str->data);
+ str->data = NULL;
+ str->size = 0;
+}
+
+void v9fs_string_null(V9fsString *str)
+{
+ v9fs_string_free(str);
+}
+
+void GCC_FMT_ATTR(2, 3)
+v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
+{
+ va_list ap;
+
+ v9fs_string_free(str);
+
+ va_start(ap, fmt);
+ str->size = g_vasprintf(&str->data, fmt, ap);
+ va_end(ap);
+}
+
+void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
+{
+ v9fs_string_free(lhs);
+ v9fs_string_sprintf(lhs, "%s", rhs->data);
+}
diff --git a/qemu/fsdev/virtio-9p-marshal.h b/qemu/fsdev/9p-marshal.h
index 5df65a835..e91b24e9c 100644
--- a/qemu/fsdev/virtio-9p-marshal.h
+++ b/qemu/fsdev/9p-marshal.h
@@ -1,5 +1,5 @@
-#ifndef _QEMU_VIRTIO_9P_MARSHAL_H
-#define _QEMU_VIRTIO_9P_MARSHAL_H
+#ifndef _QEMU_9P_MARSHAL_H
+#define _QEMU_9P_MARSHAL_H
typedef struct V9fsString
{
@@ -30,7 +30,7 @@ typedef struct V9fsStat
V9fsString muid;
/* 9p2000.u */
V9fsString extension;
- int32_t n_uid;
+ int32_t n_uid;
int32_t n_gid;
int32_t n_muid;
} V9fsStat;
@@ -81,10 +81,4 @@ extern void v9fs_string_null(V9fsString *str);
extern void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...);
extern void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs);
-ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
- const void *src, size_t size);
-ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
- int bswap, const char *fmt, ...);
-ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
- int bswap, const char *fmt, ...);
#endif
diff --git a/qemu/fsdev/Makefile.objs b/qemu/fsdev/Makefile.objs
index c27dad3f6..1b120a4a7 100644
--- a/qemu/fsdev/Makefile.objs
+++ b/qemu/fsdev/Makefile.objs
@@ -1,7 +1,7 @@
ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
# Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
# only pull in the actual virtio-9p device if we also enabled virtio.
-common-obj-y = qemu-fsdev.o virtio-9p-marshal.o
+common-obj-y = qemu-fsdev.o 9p-marshal.o 9p-iov-marshal.o
else
common-obj-y = qemu-fsdev-dummy.o
endif
diff --git a/qemu/fsdev/file-op-9p.h b/qemu/fsdev/file-op-9p.h
index 956fda091..b8c26024a 100644
--- a/qemu/fsdev/file-op-9p.h
+++ b/qemu/fsdev/file-op-9p.h
@@ -12,11 +12,8 @@
*/
#ifndef _FILEOP_H
#define _FILEOP_H
-#include <sys/types.h>
#include <dirent.h>
-#include <sys/time.h>
#include <utime.h>
-#include <sys/stat.h>
#include <sys/uio.h>
#include <sys/vfs.h>
diff --git a/qemu/fsdev/qemu-fsdev-dummy.c b/qemu/fsdev/qemu-fsdev-dummy.c
index 7dc2630a7..7622e86c1 100644
--- a/qemu/fsdev/qemu-fsdev-dummy.c
+++ b/qemu/fsdev/qemu-fsdev-dummy.c
@@ -10,8 +10,7 @@
* the COPYING file in the top-level directory.
*
*/
-#include <stdio.h>
-#include <string.h>
+#include "qemu/osdep.h"
#include "qemu-fsdev.h"
#include "qemu/config-file.h"
#include "qemu/module.h"
diff --git a/qemu/fsdev/qemu-fsdev-opts.c b/qemu/fsdev/qemu-fsdev-opts.c
index 6311c7a7e..88a4ac325 100644
--- a/qemu/fsdev/qemu-fsdev-opts.c
+++ b/qemu/fsdev/qemu-fsdev-opts.c
@@ -5,6 +5,7 @@
* later. See the COPYING file in the top-level directory.
*/
+#include "qemu/osdep.h"
#include "qemu/config-file.h"
#include "qemu/option.h"
#include "qemu/module.h"
@@ -82,4 +83,4 @@ static void fsdev_register_config(void)
qemu_add_opts(&qemu_fsdev_opts);
qemu_add_opts(&qemu_virtfs_opts);
}
-machine_init(fsdev_register_config);
+opts_init(fsdev_register_config);
diff --git a/qemu/fsdev/qemu-fsdev.c b/qemu/fsdev/qemu-fsdev.c
index ccfec139a..bf7f0b07f 100644
--- a/qemu/fsdev/qemu-fsdev.c
+++ b/qemu/fsdev/qemu-fsdev.c
@@ -10,13 +10,12 @@
* the COPYING file in the top-level directory.
*
*/
-#include <stdio.h>
-#include <string.h>
+#include "qemu/osdep.h"
#include "qemu-fsdev.h"
#include "qemu/queue.h"
-#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/config-file.h"
+#include "qemu/error-report.h"
static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
@@ -40,7 +39,7 @@ int qemu_fsdev_add(QemuOpts *opts)
bool ro = qemu_opt_get_bool(opts, "readonly", 0);
if (!fsdev_id) {
- fprintf(stderr, "fsdev: No id specified\n");
+ error_report("fsdev: No id specified");
return -1;
}
@@ -52,11 +51,11 @@ int qemu_fsdev_add(QemuOpts *opts)
}
if (i == ARRAY_SIZE(FsDrivers)) {
- fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
+ error_report("fsdev: fsdriver %s not found", fsdriver);
return -1;
}
} else {
- fprintf(stderr, "fsdev: No fsdriver specified\n");
+ error_report("fsdev: No fsdriver specified");
return -1;
}
diff --git a/qemu/fsdev/virtfs-proxy-helper.c b/qemu/fsdev/virtfs-proxy-helper.c
index 9097d15c9..54f7ad1c4 100644
--- a/qemu/fsdev/virtfs-proxy-helper.c
+++ b/qemu/fsdev/virtfs-proxy-helper.c
@@ -9,6 +9,7 @@
* the COPYING file in the top-level directory.
*/
+#include "qemu/osdep.h"
#include <sys/resource.h>
#include <getopt.h>
#include <syslog.h>
@@ -23,9 +24,9 @@
#include "qemu-common.h"
#include "qemu/sockets.h"
#include "qemu/xattr.h"
-#include "virtio-9p-marshal.h"
-#include "hw/9pfs/virtio-9p-proxy.h"
-#include "fsdev/virtio-9p-marshal.h"
+#include "9p-iov-marshal.h"
+#include "hw/9pfs/9p-proxy.h"
+#include "fsdev/9p-iov-marshal.h"
#define PROGNAME "virtfs-proxy-helper"
@@ -1128,10 +1129,19 @@ int main(int argc, char **argv)
}
}
+ if (chdir("/") < 0) {
+ do_perror("chdir");
+ goto error;
+ }
+ if (chroot(rpath) < 0) {
+ do_perror("chroot");
+ goto error;
+ }
+
get_version = false;
#ifdef FS_IOC_GETVERSION
/* check whether underlying FS support IOC_GETVERSION */
- retval = statfs(rpath, &st_fs);
+ retval = statfs("/", &st_fs);
if (!retval) {
switch (st_fs.f_type) {
case EXT2_SUPER_MAGIC:
@@ -1144,16 +1154,7 @@ int main(int argc, char **argv)
}
#endif
- if (chdir("/") < 0) {
- do_perror("chdir");
- goto error;
- }
- if (chroot(rpath) < 0) {
- do_perror("chroot");
- goto error;
- }
umask(0);
-
if (init_capabilities() < 0) {
goto error;
}
diff --git a/qemu/fsdev/virtfs-proxy-helper.texi b/qemu/fsdev/virtfs-proxy-helper.texi
index e60e3b946..6eb2d5096 100644
--- a/qemu/fsdev/virtfs-proxy-helper.texi
+++ b/qemu/fsdev/virtfs-proxy-helper.texi
@@ -1,6 +1,6 @@
@example
@c man begin SYNOPSIS
-usage: virtfs-proxy-helper options
+@command{virtfs-proxy-helper} @var{options}
@c man end
@end example
@@ -28,8 +28,8 @@ QEMU and proxy helper communicate using this socket. QEMU proxy fs
driver sends filesystem request to proxy helper and receives the
response from it.
-Proxy helper is designed so that it can drop the root privilege with
-retaining capbilities needed for doing filesystem operations only.
+The proxy helper is designed so that it can drop root privileges except
+for the capabilities needed for doing filesystem operations.
@end table
@c man end