2010-04-29 16:14:44 +04:00
|
|
|
/*
|
2015-11-18 21:05:29 +03:00
|
|
|
* 9p Posix callback
|
2010-04-29 16:14:44 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-06-01 11:05:14 +04:00
|
|
|
|
2021-05-06 16:12:23 +03:00
|
|
|
/*
|
|
|
|
* Not so fast! You might want to read the 9p developer docs first:
|
|
|
|
* https://wiki.qemu.org/Documentation/9p
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:10 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-01-07 21:18:02 +03:00
|
|
|
#include "9p.h"
|
2017-02-27 01:42:18 +03:00
|
|
|
#include "9p-local.h"
|
2015-11-18 21:31:52 +03:00
|
|
|
#include "9p-xattr.h"
|
2017-02-27 01:42:10 +03:00
|
|
|
#include "9p-util.h"
|
2014-05-03 00:22:32 +04:00
|
|
|
#include "fsdev/qemu-fsdev.h" /* local_ops */
|
2010-04-29 16:14:59 +04:00
|
|
|
#include <arpa/inet.h>
|
2010-04-29 16:14:47 +04:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
2010-04-29 16:14:59 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/xattr.h"
|
2018-02-01 14:18:31 +03:00
|
|
|
#include "qapi/error.h"
|
2016-03-20 20:16:19 +03:00
|
|
|
#include "qemu/cutils.h"
|
2016-01-22 17:12:17 +03:00
|
|
|
#include "qemu/error-report.h"
|
2018-02-01 14:18:46 +03:00
|
|
|
#include "qemu/option.h"
|
2012-01-19 10:51:11 +04:00
|
|
|
#include <libgen.h>
|
2022-02-28 01:35:12 +03:00
|
|
|
#ifdef CONFIG_LINUX
|
2011-10-12 17:41:25 +04:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#ifdef CONFIG_LINUX_MAGIC_H
|
|
|
|
#include <linux/magic.h>
|
|
|
|
#endif
|
2022-02-28 01:35:12 +03:00
|
|
|
#endif
|
2011-10-12 17:41:25 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#ifndef XFS_SUPER_MAGIC
|
|
|
|
#define XFS_SUPER_MAGIC 0x58465342
|
|
|
|
#endif
|
|
|
|
#ifndef EXT2_SUPER_MAGIC
|
|
|
|
#define EXT2_SUPER_MAGIC 0xEF53
|
|
|
|
#endif
|
|
|
|
#ifndef REISERFS_SUPER_MAGIC
|
|
|
|
#define REISERFS_SUPER_MAGIC 0x52654973
|
|
|
|
#endif
|
|
|
|
#ifndef BTRFS_SUPER_MAGIC
|
|
|
|
#define BTRFS_SUPER_MAGIC 0x9123683E
|
|
|
|
#endif
|
2010-04-29 16:14:47 +04:00
|
|
|
|
2017-02-27 01:42:10 +03:00
|
|
|
typedef struct {
|
|
|
|
int mountfd;
|
|
|
|
} LocalData;
|
2012-01-19 10:51:11 +04:00
|
|
|
|
2017-02-27 01:42:18 +03:00
|
|
|
int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags,
|
|
|
|
mode_t mode)
|
2012-01-19 10:51:11 +04:00
|
|
|
{
|
2017-02-27 01:42:18 +03:00
|
|
|
LocalData *data = fs_ctx->private;
|
2017-05-25 11:30:14 +03:00
|
|
|
int fd = data->mountfd;
|
2017-02-27 01:42:18 +03:00
|
|
|
|
2017-05-25 11:30:14 +03:00
|
|
|
while (*path && fd != -1) {
|
|
|
|
const char *c;
|
|
|
|
int next_fd;
|
|
|
|
char *head;
|
|
|
|
|
|
|
|
/* Only relative paths without consecutive slashes */
|
|
|
|
assert(*path != '/');
|
|
|
|
|
|
|
|
head = g_strdup(path);
|
2018-06-29 13:32:10 +03:00
|
|
|
c = qemu_strchrnul(path, '/');
|
2017-05-25 11:30:14 +03:00
|
|
|
if (*c) {
|
|
|
|
/* Intermediate path element */
|
|
|
|
head[c - path] = 0;
|
|
|
|
path = c + 1;
|
|
|
|
next_fd = openat_dir(fd, head);
|
|
|
|
} else {
|
|
|
|
/* Rightmost path element */
|
|
|
|
next_fd = openat_file(fd, head, flags, mode);
|
|
|
|
path = c;
|
|
|
|
}
|
|
|
|
g_free(head);
|
|
|
|
if (fd != data->mountfd) {
|
|
|
|
close_preserve_errno(fd);
|
|
|
|
}
|
|
|
|
fd = next_fd;
|
2015-03-12 09:52:30 +03:00
|
|
|
}
|
2017-02-27 01:42:18 +03:00
|
|
|
|
2017-05-25 11:30:14 +03:00
|
|
|
assert(fd != data->mountfd);
|
|
|
|
return fd;
|
2017-02-27 01:42:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int local_opendir_nofollow(FsContext *fs_ctx, const char *path)
|
|
|
|
{
|
|
|
|
return local_open_nofollow(fs_ctx, path, O_DIRECTORY | O_RDONLY, 0);
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:43:55 +03:00
|
|
|
static void renameat_preserve_errno(int odirfd, const char *opath, int ndirfd,
|
|
|
|
const char *npath)
|
|
|
|
{
|
|
|
|
int serrno = errno;
|
2022-12-19 13:20:07 +03:00
|
|
|
qemu_renameat(odirfd, opath, ndirfd, npath);
|
2017-02-27 01:43:55 +03:00
|
|
|
errno = serrno;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:20 +03:00
|
|
|
static void unlinkat_preserve_errno(int dirfd, const char *path, int flags)
|
|
|
|
{
|
|
|
|
int serrno = errno;
|
2022-12-19 13:20:07 +03:00
|
|
|
qemu_unlinkat(dirfd, path, flags);
|
2017-02-27 01:44:20 +03:00
|
|
|
errno = serrno;
|
|
|
|
}
|
|
|
|
|
2012-01-19 10:51:11 +04:00
|
|
|
#define VIRTFS_META_DIR ".virtfs_metadata"
|
2017-05-25 11:30:14 +03:00
|
|
|
#define VIRTFS_META_ROOT_FILE VIRTFS_META_DIR "_root"
|
2012-01-19 10:51:11 +04:00
|
|
|
|
2017-02-27 01:43:48 +03:00
|
|
|
static FILE *local_fopenat(int dirfd, const char *name, const char *mode)
|
2013-05-20 18:13:15 +04:00
|
|
|
{
|
|
|
|
int fd, o_mode = 0;
|
|
|
|
FILE *fp;
|
2017-02-27 01:43:48 +03:00
|
|
|
int flags;
|
2013-05-20 18:13:15 +04:00
|
|
|
/*
|
|
|
|
* only supports two modes
|
|
|
|
*/
|
|
|
|
if (mode[0] == 'r') {
|
2017-02-27 01:43:48 +03:00
|
|
|
flags = O_RDONLY;
|
2013-05-20 18:13:15 +04:00
|
|
|
} else if (mode[0] == 'w') {
|
2017-02-27 01:43:48 +03:00
|
|
|
flags = O_WRONLY | O_TRUNC | O_CREAT;
|
2013-05-20 18:13:15 +04:00
|
|
|
o_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-02-27 01:43:48 +03:00
|
|
|
fd = openat_file(dirfd, name, flags, o_mode);
|
2013-05-20 18:13:15 +04:00
|
|
|
if (fd == -1) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fp = fdopen(fd, mode);
|
|
|
|
if (!fp) {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
2012-01-19 10:51:11 +04:00
|
|
|
#define ATTR_MAX 100
|
2017-02-27 01:43:48 +03:00
|
|
|
static void local_mapped_file_attr(int dirfd, const char *name,
|
2012-01-19 10:51:11 +04:00
|
|
|
struct stat *stbuf)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char buf[ATTR_MAX];
|
2017-02-27 01:43:48 +03:00
|
|
|
int map_dirfd;
|
2012-01-19 10:51:11 +04:00
|
|
|
|
2017-05-25 11:30:14 +03:00
|
|
|
if (strcmp(name, ".")) {
|
|
|
|
map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
|
|
|
|
if (map_dirfd == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
|
2017-05-25 11:30:14 +03:00
|
|
|
fp = local_fopenat(map_dirfd, name, "r");
|
|
|
|
close_preserve_errno(map_dirfd);
|
|
|
|
} else {
|
|
|
|
fp = local_fopenat(dirfd, VIRTFS_META_ROOT_FILE, "r");
|
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
if (!fp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(buf, 0, ATTR_MAX);
|
|
|
|
while (fgets(buf, ATTR_MAX, fp)) {
|
|
|
|
if (!strncmp(buf, "virtfs.uid", 10)) {
|
2020-10-30 07:35:13 +03:00
|
|
|
stbuf->st_uid = atoi(buf + 11);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strncmp(buf, "virtfs.gid", 10)) {
|
2020-10-30 07:35:13 +03:00
|
|
|
stbuf->st_gid = atoi(buf + 11);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strncmp(buf, "virtfs.mode", 11)) {
|
2020-10-30 07:35:13 +03:00
|
|
|
stbuf->st_mode = atoi(buf + 12);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strncmp(buf, "virtfs.rdev", 11)) {
|
2020-10-30 07:35:13 +03:00
|
|
|
stbuf->st_rdev = atoi(buf + 12);
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
memset(buf, 0, ATTR_MAX);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
|
2010-04-29 16:14:47 +04:00
|
|
|
{
|
2017-02-27 01:43:48 +03:00
|
|
|
int err = -1;
|
|
|
|
char *dirpath = g_path_get_dirname(fs_path->data);
|
|
|
|
char *name = g_path_get_basename(fs_path->data);
|
|
|
|
int dirfd;
|
|
|
|
|
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dirpath);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2022-12-19 13:20:07 +03:00
|
|
|
err = qemu_fstatat(dirfd, name, stbuf, AT_SYMLINK_NOFOLLOW);
|
2010-06-15 00:34:44 +04:00
|
|
|
if (err) {
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
goto err_out;
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2011-10-13 11:51:00 +04:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
2010-06-15 00:34:44 +04:00
|
|
|
/* Actual credentials are part of extended attrs */
|
|
|
|
uid_t tmp_uid;
|
|
|
|
gid_t tmp_gid;
|
|
|
|
mode_t tmp_mode;
|
|
|
|
dev_t tmp_dev;
|
2017-02-27 01:43:48 +03:00
|
|
|
|
|
|
|
if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.uid", &tmp_uid,
|
|
|
|
sizeof(uid_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_uid = le32_to_cpu(tmp_uid);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2017-02-27 01:43:48 +03:00
|
|
|
if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.gid", &tmp_gid,
|
|
|
|
sizeof(gid_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_gid = le32_to_cpu(tmp_gid);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2017-02-27 01:43:48 +03:00
|
|
|
if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.mode", &tmp_mode,
|
|
|
|
sizeof(mode_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_mode = le32_to_cpu(tmp_mode);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2017-02-27 01:43:48 +03:00
|
|
|
if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.rdev", &tmp_dev,
|
|
|
|
sizeof(dev_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_rdev = le64_to_cpu(tmp_dev);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2017-02-27 01:43:48 +03:00
|
|
|
local_mapped_file_attr(dirfd, name, stbuf);
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
|
|
|
|
err_out:
|
2017-02-27 01:43:48 +03:00
|
|
|
close_preserve_errno(dirfd);
|
|
|
|
out:
|
|
|
|
g_free(name);
|
|
|
|
g_free(dirpath);
|
2010-06-15 00:34:44 +04:00
|
|
|
return err;
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:28 +03:00
|
|
|
static int local_set_mapped_file_attrat(int dirfd, const char *name,
|
|
|
|
FsCred *credp)
|
2012-01-19 10:51:11 +04:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2017-02-27 01:44:28 +03:00
|
|
|
int ret;
|
2012-01-19 10:51:11 +04:00
|
|
|
char buf[ATTR_MAX];
|
|
|
|
int uid = -1, gid = -1, mode = -1, rdev = -1;
|
2017-05-25 11:30:14 +03:00
|
|
|
int map_dirfd = -1, map_fd;
|
|
|
|
bool is_root = !strcmp(name, ".");
|
|
|
|
|
|
|
|
if (is_root) {
|
|
|
|
fp = local_fopenat(dirfd, VIRTFS_META_ROOT_FILE, "r");
|
|
|
|
if (!fp) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
goto update_map_file;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_mkdirat(dirfd, VIRTFS_META_DIR, 0700);
|
2017-05-25 11:30:14 +03:00
|
|
|
if (ret < 0 && errno != EEXIST) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-27 01:44:28 +03:00
|
|
|
|
2017-05-25 11:30:14 +03:00
|
|
|
map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
|
|
|
|
if (map_dirfd == -1) {
|
2017-02-27 01:44:28 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2017-05-25 11:30:14 +03:00
|
|
|
|
|
|
|
fp = local_fopenat(map_dirfd, name, "r");
|
|
|
|
if (!fp) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
goto update_map_file;
|
|
|
|
} else {
|
|
|
|
close_preserve_errno(map_dirfd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
memset(buf, 0, ATTR_MAX);
|
|
|
|
while (fgets(buf, ATTR_MAX, fp)) {
|
|
|
|
if (!strncmp(buf, "virtfs.uid", 10)) {
|
2017-02-27 01:44:28 +03:00
|
|
|
uid = atoi(buf + 11);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strncmp(buf, "virtfs.gid", 10)) {
|
2017-02-27 01:44:28 +03:00
|
|
|
gid = atoi(buf + 11);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strncmp(buf, "virtfs.mode", 11)) {
|
2017-02-27 01:44:28 +03:00
|
|
|
mode = atoi(buf + 12);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strncmp(buf, "virtfs.rdev", 11)) {
|
2017-02-27 01:44:28 +03:00
|
|
|
rdev = atoi(buf + 12);
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
memset(buf, 0, ATTR_MAX);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
update_map_file:
|
2017-05-25 11:30:14 +03:00
|
|
|
if (is_root) {
|
|
|
|
fp = local_fopenat(dirfd, VIRTFS_META_ROOT_FILE, "w");
|
|
|
|
} else {
|
|
|
|
fp = local_fopenat(map_dirfd, name, "w");
|
|
|
|
/* We can't go this far with map_dirfd not being a valid file descriptor
|
|
|
|
* but some versions of gcc aren't smart enough to see it.
|
|
|
|
*/
|
|
|
|
if (map_dirfd != -1) {
|
|
|
|
close_preserve_errno(map_dirfd);
|
|
|
|
}
|
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
if (!fp) {
|
2017-02-27 01:44:28 +03:00
|
|
|
return -1;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
|
2017-05-25 11:30:14 +03:00
|
|
|
map_fd = fileno(fp);
|
|
|
|
assert(map_fd != -1);
|
|
|
|
ret = fchmod(map_fd, 0600);
|
|
|
|
assert(ret == 0);
|
|
|
|
|
2012-01-19 10:51:11 +04:00
|
|
|
if (credp->fc_uid != -1) {
|
|
|
|
uid = credp->fc_uid;
|
|
|
|
}
|
|
|
|
if (credp->fc_gid != -1) {
|
|
|
|
gid = credp->fc_gid;
|
|
|
|
}
|
2018-06-29 13:32:10 +03:00
|
|
|
if (credp->fc_mode != (mode_t)-1) {
|
2012-01-19 10:51:11 +04:00
|
|
|
mode = credp->fc_mode;
|
|
|
|
}
|
|
|
|
if (credp->fc_rdev != -1) {
|
|
|
|
rdev = credp->fc_rdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uid != -1) {
|
|
|
|
fprintf(fp, "virtfs.uid=%d\n", uid);
|
|
|
|
}
|
|
|
|
if (gid != -1) {
|
|
|
|
fprintf(fp, "virtfs.gid=%d\n", gid);
|
|
|
|
}
|
|
|
|
if (mode != -1) {
|
|
|
|
fprintf(fp, "virtfs.mode=%d\n", mode);
|
|
|
|
}
|
|
|
|
if (rdev != -1) {
|
|
|
|
fprintf(fp, "virtfs.rdev=%d\n", rdev);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
2017-02-27 01:44:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)
|
|
|
|
{
|
2017-08-10 15:21:04 +03:00
|
|
|
struct stat stbuf;
|
2017-02-27 01:44:28 +03:00
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
/* FIXME: this should be handled with fchmodat(AT_SYMLINK_NOFOLLOW).
|
2017-08-10 15:21:04 +03:00
|
|
|
* Unfortunately, the linux kernel doesn't implement it yet.
|
2017-02-27 01:44:28 +03:00
|
|
|
*/
|
2017-08-10 15:21:04 +03:00
|
|
|
|
|
|
|
/* First, we clear non-racing symlinks out of the way. */
|
2022-12-19 13:20:07 +03:00
|
|
|
if (qemu_fstatat(dirfd, name, &stbuf, AT_SYMLINK_NOFOLLOW)) {
|
2017-08-10 15:21:04 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (S_ISLNK(stbuf.st_mode)) {
|
|
|
|
errno = ELOOP;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-09-04 10:24:53 +03:00
|
|
|
fd = openat_file(dirfd, name, O_RDONLY | O_PATH_9P_UTIL | O_NOFOLLOW, 0);
|
2017-08-10 15:21:04 +03:00
|
|
|
#if O_PATH_9P_UTIL == 0
|
2017-09-04 10:24:53 +03:00
|
|
|
/* Fallback for systems that don't support O_PATH: we depend on the file
|
|
|
|
* being readable or writable.
|
|
|
|
*/
|
2017-02-27 01:44:28 +03:00
|
|
|
if (fd == -1) {
|
|
|
|
/* In case the file is writable-only and isn't a directory. */
|
|
|
|
if (errno == EACCES) {
|
|
|
|
fd = openat_file(dirfd, name, O_WRONLY, 0);
|
|
|
|
}
|
|
|
|
if (fd == -1 && errno == EISDIR) {
|
|
|
|
errno = EACCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = fchmod(fd, mode);
|
2017-08-10 15:21:04 +03:00
|
|
|
#else
|
2017-09-04 10:24:53 +03:00
|
|
|
/* Access modes are ignored when O_PATH is supported. If name is a symbolic
|
|
|
|
* link, O_PATH | O_NOFOLLOW causes openat(2) to return a file descriptor
|
|
|
|
* referring to the symbolic link.
|
|
|
|
*/
|
2017-08-10 15:21:04 +03:00
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we handle racing symlinks. */
|
|
|
|
ret = fstat(fd, &stbuf);
|
|
|
|
if (!ret) {
|
|
|
|
if (S_ISLNK(stbuf.st_mode)) {
|
|
|
|
errno = ELOOP;
|
|
|
|
ret = -1;
|
|
|
|
} else {
|
|
|
|
char *proc_path = g_strdup_printf("/proc/self/fd/%d", fd);
|
|
|
|
ret = chmod(proc_path, mode);
|
|
|
|
g_free(proc_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2017-02-27 01:44:28 +03:00
|
|
|
close_preserve_errno(fd);
|
2012-01-19 10:51:11 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:28 +03:00
|
|
|
static int local_set_xattrat(int dirfd, const char *path, FsCred *credp)
|
2010-04-29 16:14:47 +04:00
|
|
|
{
|
2010-06-15 00:34:41 +04:00
|
|
|
int err;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2010-06-15 00:34:41 +04:00
|
|
|
if (credp->fc_uid != -1) {
|
2014-08-03 15:32:55 +04:00
|
|
|
uint32_t tmp_uid = cpu_to_le32(credp->fc_uid);
|
2017-02-27 01:44:28 +03:00
|
|
|
err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.uid", &tmp_uid,
|
|
|
|
sizeof(uid_t), 0);
|
2010-06-15 00:34:41 +04:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
2010-06-15 00:34:41 +04:00
|
|
|
if (credp->fc_gid != -1) {
|
2014-08-03 15:32:55 +04:00
|
|
|
uint32_t tmp_gid = cpu_to_le32(credp->fc_gid);
|
2017-02-27 01:44:28 +03:00
|
|
|
err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.gid", &tmp_gid,
|
|
|
|
sizeof(gid_t), 0);
|
2010-06-15 00:34:41 +04:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
2018-06-29 13:32:10 +03:00
|
|
|
if (credp->fc_mode != (mode_t)-1) {
|
2014-08-03 15:32:55 +04:00
|
|
|
uint32_t tmp_mode = cpu_to_le32(credp->fc_mode);
|
2017-02-27 01:44:28 +03:00
|
|
|
err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.mode", &tmp_mode,
|
|
|
|
sizeof(mode_t), 0);
|
2010-06-15 00:34:41 +04:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
2010-06-15 00:34:41 +04:00
|
|
|
if (credp->fc_rdev != -1) {
|
2014-08-03 15:32:55 +04:00
|
|
|
uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev);
|
2017-02-27 01:44:28 +03:00
|
|
|
err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.rdev", &tmp_rdev,
|
|
|
|
sizeof(dev_t), 0);
|
2010-06-15 00:34:41 +04:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:54 +03:00
|
|
|
static int local_set_cred_passthrough(FsContext *fs_ctx, int dirfd,
|
|
|
|
const char *name, FsCred *credp)
|
2010-06-15 00:34:45 +04:00
|
|
|
{
|
2017-02-27 01:44:54 +03:00
|
|
|
if (fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
|
2017-03-06 19:34:01 +03:00
|
|
|
AT_SYMLINK_NOFOLLOW) < 0) {
|
2010-09-02 09:39:07 +04:00
|
|
|
/*
|
|
|
|
* If we fail to change ownership and if we are
|
|
|
|
* using security model none. Ignore the error
|
|
|
|
*/
|
2011-10-13 11:51:00 +04:00
|
|
|
if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
|
2017-02-27 01:44:54 +03:00
|
|
|
return -1;
|
2010-09-02 09:39:07 +04:00
|
|
|
}
|
2010-06-15 00:34:45 +04:00
|
|
|
}
|
2012-01-19 10:51:12 +04:00
|
|
|
|
2017-02-27 01:44:54 +03:00
|
|
|
return fchmodat_nofollow(dirfd, name, credp->fc_mode & 07777);
|
2010-06-15 00:34:45 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
|
|
|
|
char *buf, size_t bufsz)
|
2010-04-29 16:14:47 +04:00
|
|
|
{
|
2010-06-15 00:34:47 +04:00
|
|
|
ssize_t tsize = -1;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2012-01-19 10:51:11 +04:00
|
|
|
if ((fs_ctx->export_flags & V9FS_SM_MAPPED) ||
|
|
|
|
(fs_ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
|
2010-06-15 00:34:47 +04:00
|
|
|
int fd;
|
2017-02-27 01:43:40 +03:00
|
|
|
|
|
|
|
fd = local_open_nofollow(fs_ctx, fs_path->data, O_RDONLY, 0);
|
2010-06-15 00:34:47 +04:00
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2022-10-23 12:04:22 +03:00
|
|
|
tsize = RETRY_ON_EINTR(read(fd, (void *)buf, bufsz));
|
2017-02-27 01:43:40 +03:00
|
|
|
close_preserve_errno(fd);
|
2011-10-13 11:51:00 +04:00
|
|
|
} else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
|
|
|
|
(fs_ctx->export_flags & V9FS_SM_NONE)) {
|
2017-02-27 01:43:40 +03:00
|
|
|
char *dirpath = g_path_get_dirname(fs_path->data);
|
|
|
|
char *name = g_path_get_basename(fs_path->data);
|
|
|
|
int dirfd;
|
|
|
|
|
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dirpath);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsize = readlinkat(dirfd, name, buf, bufsz);
|
|
|
|
close_preserve_errno(dirfd);
|
|
|
|
out:
|
|
|
|
g_free(name);
|
|
|
|
g_free(dirpath);
|
2010-06-15 00:34:47 +04:00
|
|
|
}
|
|
|
|
return tsize;
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static int local_close(FsContext *ctx, V9fsFidOpenState *fs)
|
2010-04-29 16:14:47 +04:00
|
|
|
{
|
2011-10-25 10:40:40 +04:00
|
|
|
return close(fs->fd);
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static int local_closedir(FsContext *ctx, V9fsFidOpenState *fs)
|
2010-04-29 16:14:47 +04:00
|
|
|
{
|
2016-06-06 12:52:34 +03:00
|
|
|
return closedir(fs->dir.stream);
|
2010-04-29 16:14:47 +04:00
|
|
|
}
|
2010-04-29 16:14:44 +04:00
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static int local_open(FsContext *ctx, V9fsPath *fs_path,
|
|
|
|
int flags, V9fsFidOpenState *fs)
|
2010-04-29 16:14:55 +04:00
|
|
|
{
|
2017-02-27 01:41:55 +03:00
|
|
|
int fd;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:42:18 +03:00
|
|
|
fd = local_open_nofollow(ctx, fs_path->data, flags, 0);
|
2017-02-27 01:41:55 +03:00
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fs->fd = fd;
|
2011-10-25 10:40:40 +04:00
|
|
|
return fs->fd;
|
2010-04-29 16:14:55 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static int local_opendir(FsContext *ctx,
|
|
|
|
V9fsPath *fs_path, V9fsFidOpenState *fs)
|
2010-04-29 16:14:55 +04:00
|
|
|
{
|
2017-02-27 01:42:18 +03:00
|
|
|
int dirfd;
|
2017-02-27 01:41:55 +03:00
|
|
|
DIR *stream;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:42:18 +03:00
|
|
|
dirfd = local_opendir_nofollow(ctx, fs_path->data);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:42:18 +03:00
|
|
|
stream = fdopendir(dirfd);
|
2017-02-27 01:41:55 +03:00
|
|
|
if (!stream) {
|
2017-03-06 19:34:01 +03:00
|
|
|
close(dirfd);
|
2011-10-25 10:40:40 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2017-02-27 01:41:55 +03:00
|
|
|
fs->dir.stream = stream;
|
2011-10-25 10:40:40 +04:00
|
|
|
return 0;
|
2010-04-29 16:14:55 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs)
|
2010-04-29 16:14:56 +04:00
|
|
|
{
|
2016-06-06 12:52:34 +03:00
|
|
|
rewinddir(fs->dir.stream);
|
2010-04-29 16:14:56 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs)
|
2010-04-29 16:14:56 +04:00
|
|
|
{
|
2016-06-06 12:52:34 +03:00
|
|
|
return telldir(fs->dir.stream);
|
2010-04-29 16:14:56 +04:00
|
|
|
}
|
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
static bool local_is_mapped_file_metadata(FsContext *fs_ctx, const char *name)
|
|
|
|
{
|
2017-05-25 11:30:14 +03:00
|
|
|
return
|
|
|
|
!strcmp(name, VIRTFS_META_DIR) || !strcmp(name, VIRTFS_META_ROOT_FILE);
|
2017-05-05 15:48:08 +03:00
|
|
|
}
|
|
|
|
|
2016-06-06 12:52:34 +03:00
|
|
|
static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs)
|
2010-04-29 16:14:56 +04:00
|
|
|
{
|
2016-06-06 12:52:34 +03:00
|
|
|
struct dirent *entry;
|
2012-01-19 10:51:11 +04:00
|
|
|
|
|
|
|
again:
|
2016-06-06 12:52:34 +03:00
|
|
|
entry = readdir(fs->dir.stream);
|
|
|
|
if (!entry) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-02-28 01:35:15 +03:00
|
|
|
#ifdef CONFIG_DARWIN
|
|
|
|
int off;
|
|
|
|
off = telldir(fs->dir.stream);
|
|
|
|
/* If telldir fails, fail the entire readdir call */
|
|
|
|
if (off < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
entry->d_seekoff = off;
|
|
|
|
#endif
|
2016-06-06 12:52:34 +03:00
|
|
|
|
2014-08-22 13:22:21 +04:00
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED) {
|
|
|
|
entry->d_type = DT_UNKNOWN;
|
|
|
|
} else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2017-05-05 15:48:08 +03:00
|
|
|
if (local_is_mapped_file_metadata(ctx, entry->d_name)) {
|
2017-05-25 11:30:14 +03:00
|
|
|
/* skip the meta data */
|
2012-01-19 10:51:11 +04:00
|
|
|
goto again;
|
|
|
|
}
|
2014-08-22 13:22:21 +04:00
|
|
|
entry->d_type = DT_UNKNOWN;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
2016-06-06 12:52:34 +03:00
|
|
|
|
|
|
|
return entry;
|
2010-04-29 16:14:56 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
|
2010-04-29 16:14:56 +04:00
|
|
|
{
|
2016-06-06 12:52:34 +03:00
|
|
|
seekdir(fs->dir.stream, off);
|
2010-04-29 16:14:56 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs,
|
|
|
|
const struct iovec *iov,
|
2010-10-08 10:00:16 +04:00
|
|
|
int iovcnt, off_t offset)
|
2010-04-29 16:14:56 +04:00
|
|
|
{
|
2010-10-08 10:00:16 +04:00
|
|
|
#ifdef CONFIG_PREADV
|
2011-10-25 10:40:40 +04:00
|
|
|
return preadv(fs->fd, iov, iovcnt, offset);
|
2010-10-08 10:00:16 +04:00
|
|
|
#else
|
2011-10-25 10:40:40 +04:00
|
|
|
int err = lseek(fs->fd, offset, SEEK_SET);
|
2010-10-08 10:00:16 +04:00
|
|
|
if (err == -1) {
|
|
|
|
return err;
|
|
|
|
} else {
|
2011-10-25 10:40:40 +04:00
|
|
|
return readv(fs->fd, iov, iovcnt);
|
2010-10-08 10:00:16 +04:00
|
|
|
}
|
|
|
|
#endif
|
2010-04-29 16:14:56 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 10:40:40 +04:00
|
|
|
static ssize_t local_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
|
|
|
|
const struct iovec *iov,
|
2011-09-09 13:44:18 +04:00
|
|
|
int iovcnt, off_t offset)
|
2010-04-29 16:14:58 +04:00
|
|
|
{
|
2017-01-23 11:46:13 +03:00
|
|
|
ssize_t ret;
|
2010-10-08 10:00:16 +04:00
|
|
|
#ifdef CONFIG_PREADV
|
2011-10-25 10:40:40 +04:00
|
|
|
ret = pwritev(fs->fd, iov, iovcnt, offset);
|
2010-10-08 10:00:16 +04:00
|
|
|
#else
|
2011-10-25 10:40:40 +04:00
|
|
|
int err = lseek(fs->fd, offset, SEEK_SET);
|
2010-10-08 10:00:16 +04:00
|
|
|
if (err == -1) {
|
|
|
|
return err;
|
|
|
|
} else {
|
2011-10-25 10:40:40 +04:00
|
|
|
ret = writev(fs->fd, iov, iovcnt);
|
2010-10-08 10:00:16 +04:00
|
|
|
}
|
|
|
|
#endif
|
2011-10-12 17:41:23 +04:00
|
|
|
#ifdef CONFIG_SYNC_FILE_RANGE
|
|
|
|
if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) {
|
|
|
|
/*
|
|
|
|
* Initiate a writeback. This is not a data integrity sync.
|
|
|
|
* We want to ensure that we don't leave dirty pages in the cache
|
2023-07-14 14:13:50 +03:00
|
|
|
* after write when writeout=immediate is specified.
|
2011-10-12 17:41:23 +04:00
|
|
|
*/
|
2011-10-25 10:40:40 +04:00
|
|
|
sync_file_range(fs->fd, offset, ret,
|
2011-10-12 17:41:23 +04:00
|
|
|
SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return ret;
|
2010-04-29 16:14:58 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
|
2010-04-29 16:14:59 +04:00
|
|
|
{
|
2017-02-27 01:44:28 +03:00
|
|
|
char *dirpath = g_path_get_dirname(fs_path->data);
|
|
|
|
char *name = g_path_get_basename(fs_path->data);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
int ret = -1;
|
2017-02-27 01:44:28 +03:00
|
|
|
int dirfd;
|
|
|
|
|
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dirpath);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2011-10-13 11:51:00 +04:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
2017-02-27 01:44:28 +03:00
|
|
|
ret = local_set_xattrat(dirfd, name, credp);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2017-02-27 01:44:28 +03:00
|
|
|
ret = local_set_mapped_file_attrat(dirfd, name, credp);
|
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_NONE) {
|
|
|
|
ret = fchmodat_nofollow(dirfd, name, credp->fc_mode);
|
2010-06-15 00:34:42 +04:00
|
|
|
}
|
2017-02-27 01:44:28 +03:00
|
|
|
close_preserve_errno(dirfd);
|
|
|
|
|
|
|
|
out:
|
|
|
|
g_free(dirpath);
|
|
|
|
g_free(name);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
return ret;
|
2010-04-29 16:14:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
|
|
|
|
const char *name, FsCred *credp)
|
2010-04-29 16:14:59 +04:00
|
|
|
{
|
2010-06-15 00:34:48 +04:00
|
|
|
int err = -1;
|
2017-02-27 01:44:54 +03:00
|
|
|
int dirfd;
|
2010-06-15 00:34:48 +04:00
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
local_is_mapped_file_metadata(fs_ctx, name)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:54 +03:00
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:44:54 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2022-02-28 01:35:20 +03:00
|
|
|
err = qemu_mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0);
|
2010-06-15 00:34:48 +04:00
|
|
|
if (err == -1) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:48 +04:00
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
|
2017-02-27 01:44:54 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
|
|
|
err = local_set_xattrat(dirfd, name, credp);
|
|
|
|
} else {
|
|
|
|
err = local_set_mapped_file_attrat(dirfd, name, credp);
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
if (err == -1) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
2017-02-27 01:44:54 +03:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_NONE) {
|
2022-02-28 01:35:20 +03:00
|
|
|
err = qemu_mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev);
|
2010-06-15 00:34:48 +04:00
|
|
|
if (err == -1) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:48 +04:00
|
|
|
}
|
2017-02-27 01:44:54 +03:00
|
|
|
err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
|
2010-06-15 00:34:48 +04:00
|
|
|
if (err == -1) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:48 +04:00
|
|
|
|
|
|
|
err_end:
|
2017-02-27 01:44:54 +03:00
|
|
|
unlinkat_preserve_errno(dirfd, name, 0);
|
2011-09-09 13:44:18 +04:00
|
|
|
out:
|
2017-02-27 01:44:54 +03:00
|
|
|
close_preserve_errno(dirfd);
|
2010-06-15 00:34:48 +04:00
|
|
|
return err;
|
2010-04-29 16:14:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
|
|
|
|
const char *name, FsCred *credp)
|
2010-04-29 16:14:59 +04:00
|
|
|
{
|
2010-06-15 00:34:46 +04:00
|
|
|
int err = -1;
|
2017-02-27 01:45:02 +03:00
|
|
|
int dirfd;
|
2010-06-15 00:34:46 +04:00
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
local_is_mapped_file_metadata(fs_ctx, name)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:45:02 +03:00
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:45:02 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2022-12-19 13:20:07 +03:00
|
|
|
err = qemu_mkdirat(dirfd, name, fs_ctx->dmode);
|
2010-06-15 00:34:46 +04:00
|
|
|
if (err == -1) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:46 +04:00
|
|
|
}
|
2017-02-27 01:45:02 +03:00
|
|
|
credp->fc_mode = credp->fc_mode | S_IFDIR;
|
|
|
|
|
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
|
|
|
err = local_set_xattrat(dirfd, name, credp);
|
|
|
|
} else {
|
|
|
|
err = local_set_mapped_file_attrat(dirfd, name, credp);
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
if (err == -1) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
2017-02-27 01:45:02 +03:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_NONE) {
|
2022-12-19 13:20:07 +03:00
|
|
|
err = qemu_mkdirat(dirfd, name, credp->fc_mode);
|
2010-06-15 00:34:46 +04:00
|
|
|
if (err == -1) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:46 +04:00
|
|
|
}
|
2017-02-27 01:45:02 +03:00
|
|
|
err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
|
2010-06-15 00:34:46 +04:00
|
|
|
if (err == -1) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:46 +04:00
|
|
|
|
|
|
|
err_end:
|
2017-02-27 01:45:02 +03:00
|
|
|
unlinkat_preserve_errno(dirfd, name, AT_REMOVEDIR);
|
2011-09-09 13:44:18 +04:00
|
|
|
out:
|
2017-02-27 01:45:02 +03:00
|
|
|
close_preserve_errno(dirfd);
|
2010-06-15 00:34:46 +04:00
|
|
|
return err;
|
2010-04-29 16:14:59 +04:00
|
|
|
}
|
|
|
|
|
2011-12-04 21:05:28 +04:00
|
|
|
static int local_fstat(FsContext *fs_ctx, int fid_type,
|
2011-10-25 10:40:40 +04:00
|
|
|
V9fsFidOpenState *fs, struct stat *stbuf)
|
2010-04-29 16:14:59 +04:00
|
|
|
{
|
2011-12-04 21:05:28 +04:00
|
|
|
int err, fd;
|
|
|
|
|
|
|
|
if (fid_type == P9_FID_DIR) {
|
2016-06-06 12:52:34 +03:00
|
|
|
fd = dirfd(fs->dir.stream);
|
2011-12-04 21:05:28 +04:00
|
|
|
} else {
|
|
|
|
fd = fs->fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = fstat(fd, stbuf);
|
2010-06-15 00:34:44 +04:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2011-10-13 11:51:00 +04:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
2010-06-15 00:34:44 +04:00
|
|
|
/* Actual credentials are part of extended attrs */
|
|
|
|
uid_t tmp_uid;
|
|
|
|
gid_t tmp_gid;
|
|
|
|
mode_t tmp_mode;
|
|
|
|
dev_t tmp_dev;
|
|
|
|
|
2022-02-28 01:35:19 +03:00
|
|
|
if (qemu_fgetxattr(fd, "user.virtfs.uid",
|
|
|
|
&tmp_uid, sizeof(uid_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_uid = le32_to_cpu(tmp_uid);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2022-02-28 01:35:19 +03:00
|
|
|
if (qemu_fgetxattr(fd, "user.virtfs.gid",
|
|
|
|
&tmp_gid, sizeof(gid_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_gid = le32_to_cpu(tmp_gid);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2022-02-28 01:35:19 +03:00
|
|
|
if (qemu_fgetxattr(fd, "user.virtfs.mode",
|
|
|
|
&tmp_mode, sizeof(mode_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_mode = le32_to_cpu(tmp_mode);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2022-02-28 01:35:19 +03:00
|
|
|
if (qemu_fgetxattr(fd, "user.virtfs.rdev",
|
|
|
|
&tmp_dev, sizeof(dev_t)) > 0) {
|
2014-08-03 15:32:55 +04:00
|
|
|
stbuf->st_rdev = le64_to_cpu(tmp_dev);
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
|
|
|
errno = EOPNOTSUPP;
|
|
|
|
return -1;
|
2010-06-15 00:34:44 +04:00
|
|
|
}
|
|
|
|
return err;
|
2010-04-29 16:14:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
|
2011-10-25 10:40:40 +04:00
|
|
|
int flags, FsCred *credp, V9fsFidOpenState *fs)
|
2010-04-29 16:14:59 +04:00
|
|
|
{
|
2010-06-15 00:34:45 +04:00
|
|
|
int fd = -1;
|
|
|
|
int err = -1;
|
2017-02-27 01:45:09 +03:00
|
|
|
int dirfd;
|
2010-06-15 00:34:45 +04:00
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
local_is_mapped_file_metadata(fs_ctx, name)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-20 18:13:15 +04:00
|
|
|
/*
|
|
|
|
* Mark all the open to not follow symlinks
|
|
|
|
*/
|
|
|
|
flags |= O_NOFOLLOW;
|
|
|
|
|
2017-02-27 01:45:09 +03:00
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2010-06-15 00:34:45 +04:00
|
|
|
/* Determine the security model */
|
2017-02-27 01:45:09 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2017-06-29 16:11:50 +03:00
|
|
|
fd = openat_file(dirfd, name, flags, fs_ctx->fmode);
|
2010-06-15 00:34:45 +04:00
|
|
|
if (fd == -1) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:45 +04:00
|
|
|
}
|
2020-10-30 07:35:13 +03:00
|
|
|
credp->fc_mode = credp->fc_mode | S_IFREG;
|
2017-02-27 01:45:09 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
2023-07-14 14:13:50 +03:00
|
|
|
/* Set client credentials in xattr */
|
2017-02-27 01:45:09 +03:00
|
|
|
err = local_set_xattrat(dirfd, name, credp);
|
|
|
|
} else {
|
|
|
|
err = local_set_mapped_file_attrat(dirfd, name, credp);
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
if (err == -1) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
2011-10-13 11:51:00 +04:00
|
|
|
} else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
|
|
|
|
(fs_ctx->export_flags & V9FS_SM_NONE)) {
|
2017-02-27 01:45:09 +03:00
|
|
|
fd = openat_file(dirfd, name, flags, credp->fc_mode);
|
2010-06-15 00:34:45 +04:00
|
|
|
if (fd == -1) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:45 +04:00
|
|
|
}
|
2017-02-27 01:45:09 +03:00
|
|
|
err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
|
2010-06-15 00:34:45 +04:00
|
|
|
if (err == -1) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
err = fd;
|
2011-10-25 10:40:40 +04:00
|
|
|
fs->fd = fd;
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:45 +04:00
|
|
|
|
|
|
|
err_end:
|
2017-02-27 01:45:09 +03:00
|
|
|
unlinkat_preserve_errno(dirfd, name,
|
|
|
|
flags & O_DIRECTORY ? AT_REMOVEDIR : 0);
|
|
|
|
close_preserve_errno(fd);
|
2011-09-09 13:44:18 +04:00
|
|
|
out:
|
2017-02-27 01:45:09 +03:00
|
|
|
close_preserve_errno(dirfd);
|
2010-06-15 00:34:45 +04:00
|
|
|
return err;
|
2010-04-29 16:14:59 +04:00
|
|
|
}
|
|
|
|
|
2010-06-15 00:34:41 +04:00
|
|
|
|
2010-06-15 00:34:47 +04:00
|
|
|
static int local_symlink(FsContext *fs_ctx, const char *oldpath,
|
2011-09-09 13:44:18 +04:00
|
|
|
V9fsPath *dir_path, const char *name, FsCred *credp)
|
2010-04-29 16:14:59 +04:00
|
|
|
{
|
2010-06-15 00:34:47 +04:00
|
|
|
int err = -1;
|
2017-02-27 01:44:46 +03:00
|
|
|
int dirfd;
|
2010-06-15 00:34:47 +04:00
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
local_is_mapped_file_metadata(fs_ctx, name)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:46 +03:00
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2010-06-15 00:34:47 +04:00
|
|
|
/* Determine the security model */
|
2017-02-27 01:44:46 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2010-06-15 00:34:47 +04:00
|
|
|
int fd;
|
|
|
|
ssize_t oldpath_size, write_size;
|
2017-02-27 01:44:46 +03:00
|
|
|
|
|
|
|
fd = openat_file(dirfd, name, O_CREAT | O_EXCL | O_RDWR,
|
2017-06-29 16:11:50 +03:00
|
|
|
fs_ctx->fmode);
|
2010-06-15 00:34:47 +04:00
|
|
|
if (fd == -1) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:47 +04:00
|
|
|
}
|
|
|
|
/* Write the oldpath (target) to the file. */
|
2011-02-02 07:50:33 +03:00
|
|
|
oldpath_size = strlen(oldpath);
|
2022-10-23 12:04:22 +03:00
|
|
|
write_size = RETRY_ON_EINTR(write(fd, (void *)oldpath, oldpath_size));
|
2017-02-27 01:44:46 +03:00
|
|
|
close_preserve_errno(fd);
|
2010-06-15 00:34:47 +04:00
|
|
|
|
|
|
|
if (write_size != oldpath_size) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
2023-07-14 14:13:50 +03:00
|
|
|
/* Set client credentials in symlink's xattr */
|
2017-02-27 01:44:46 +03:00
|
|
|
credp->fc_mode = credp->fc_mode | S_IFLNK;
|
2012-01-19 10:51:11 +04:00
|
|
|
|
2017-02-27 01:44:46 +03:00
|
|
|
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
|
|
|
err = local_set_xattrat(dirfd, name, credp);
|
|
|
|
} else {
|
|
|
|
err = local_set_mapped_file_attrat(dirfd, name, credp);
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
if (err == -1) {
|
|
|
|
goto err_end;
|
|
|
|
}
|
2017-02-27 01:44:46 +03:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
|
|
|
|
fs_ctx->export_flags & V9FS_SM_NONE) {
|
|
|
|
err = symlinkat(oldpath, dirfd, name);
|
2010-06-15 00:34:47 +04:00
|
|
|
if (err) {
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:47 +04:00
|
|
|
}
|
2017-02-27 01:44:46 +03:00
|
|
|
err = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
|
|
|
|
AT_SYMLINK_NOFOLLOW);
|
2010-06-15 00:34:47 +04:00
|
|
|
if (err == -1) {
|
2010-09-02 09:39:07 +04:00
|
|
|
/*
|
|
|
|
* If we fail to change ownership and if we are
|
|
|
|
* using security model none. Ignore the error
|
|
|
|
*/
|
2011-10-13 11:51:00 +04:00
|
|
|
if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
|
2010-09-02 09:39:07 +04:00
|
|
|
goto err_end;
|
2017-02-27 01:44:46 +03:00
|
|
|
} else {
|
2010-09-02 09:39:07 +04:00
|
|
|
err = 0;
|
2017-02-27 01:44:46 +03:00
|
|
|
}
|
2010-06-15 00:34:47 +04:00
|
|
|
}
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
goto out;
|
2010-06-15 00:34:47 +04:00
|
|
|
|
|
|
|
err_end:
|
2017-02-27 01:44:46 +03:00
|
|
|
unlinkat_preserve_errno(dirfd, name, 0);
|
2011-09-09 13:44:18 +04:00
|
|
|
out:
|
2017-02-27 01:44:46 +03:00
|
|
|
close_preserve_errno(dirfd);
|
2010-06-15 00:34:47 +04:00
|
|
|
return err;
|
2010-04-29 16:14:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_link(FsContext *ctx, V9fsPath *oldpath,
|
|
|
|
V9fsPath *dirpath, const char *name)
|
2010-04-29 16:14:59 +04:00
|
|
|
{
|
2017-02-27 01:44:20 +03:00
|
|
|
char *odirpath = g_path_get_dirname(oldpath->data);
|
|
|
|
char *oname = g_path_get_basename(oldpath->data);
|
|
|
|
int ret = -1;
|
|
|
|
int odirfd, ndirfd;
|
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
local_is_mapped_file_metadata(ctx, name)) {
|
|
|
|
errno = EINVAL;
|
2020-01-20 17:11:39 +03:00
|
|
|
goto out;
|
2017-05-05 15:48:08 +03:00
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:20 +03:00
|
|
|
odirfd = local_opendir_nofollow(ctx, odirpath);
|
|
|
|
if (odirfd == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-29 16:14:59 +04:00
|
|
|
|
2017-02-27 01:44:20 +03:00
|
|
|
ndirfd = local_opendir_nofollow(ctx, dirpath->data);
|
|
|
|
if (ndirfd == -1) {
|
|
|
|
close_preserve_errno(odirfd);
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:44:20 +03:00
|
|
|
ret = linkat(odirfd, oname, ndirfd, name, 0);
|
2017-02-27 01:44:11 +03:00
|
|
|
if (ret < 0) {
|
2017-02-27 01:44:20 +03:00
|
|
|
goto out_close;
|
2017-02-27 01:44:11 +03:00
|
|
|
}
|
2012-01-19 10:51:11 +04:00
|
|
|
|
|
|
|
/* now link the virtfs_metadata files */
|
2017-02-27 01:44:11 +03:00
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2017-02-27 01:44:20 +03:00
|
|
|
int omap_dirfd, nmap_dirfd;
|
|
|
|
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_mkdirat(ndirfd, VIRTFS_META_DIR, 0700);
|
2017-02-27 01:44:20 +03:00
|
|
|
if (ret < 0 && errno != EEXIST) {
|
|
|
|
goto err_undo_link;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
2017-02-27 01:44:20 +03:00
|
|
|
|
|
|
|
omap_dirfd = openat_dir(odirfd, VIRTFS_META_DIR);
|
|
|
|
if (omap_dirfd == -1) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
nmap_dirfd = openat_dir(ndirfd, VIRTFS_META_DIR);
|
|
|
|
if (nmap_dirfd == -1) {
|
|
|
|
close_preserve_errno(omap_dirfd);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = linkat(omap_dirfd, oname, nmap_dirfd, name, 0);
|
|
|
|
close_preserve_errno(nmap_dirfd);
|
|
|
|
close_preserve_errno(omap_dirfd);
|
2012-01-19 10:51:11 +04:00
|
|
|
if (ret < 0 && errno != ENOENT) {
|
2017-02-27 01:44:20 +03:00
|
|
|
goto err_undo_link;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
2010-04-29 16:14:59 +04:00
|
|
|
|
2017-02-27 01:44:20 +03:00
|
|
|
ret = 0;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
2017-02-27 01:44:20 +03:00
|
|
|
goto out_close;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:44:20 +03:00
|
|
|
err:
|
|
|
|
ret = -1;
|
|
|
|
err_undo_link:
|
|
|
|
unlinkat_preserve_errno(ndirfd, name, 0);
|
|
|
|
out_close:
|
|
|
|
close_preserve_errno(ndirfd);
|
|
|
|
close_preserve_errno(odirfd);
|
2017-02-27 01:44:11 +03:00
|
|
|
out:
|
2017-02-27 01:44:20 +03:00
|
|
|
g_free(oname);
|
|
|
|
g_free(odirpath);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
return ret;
|
2010-04-29 16:15:00 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size)
|
2010-04-29 16:15:00 +04:00
|
|
|
{
|
2017-02-27 01:43:32 +03:00
|
|
|
int fd, ret;
|
2010-04-29 16:15:00 +04:00
|
|
|
|
2017-02-27 01:43:32 +03:00
|
|
|
fd = local_open_nofollow(ctx, fs_path->data, O_WRONLY, 0);
|
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
2017-02-27 01:43:32 +03:00
|
|
|
ret = ftruncate(fd, size);
|
|
|
|
close_preserve_errno(fd);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
return ret;
|
2010-04-29 16:15:00 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
|
2010-04-29 16:15:00 +04:00
|
|
|
{
|
2017-02-27 01:44:37 +03:00
|
|
|
char *dirpath = g_path_get_dirname(fs_path->data);
|
|
|
|
char *name = g_path_get_basename(fs_path->data);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
int ret = -1;
|
2017-02-27 01:44:37 +03:00
|
|
|
int dirfd;
|
|
|
|
|
|
|
|
dirfd = local_opendir_nofollow(fs_ctx, dirpath);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
virtio-9p: Implement server side of setattr for 9P2000.L protocol.
SYNOPSIS
size[4] Tsetattr tag[2] attr[n]
size[4] Rsetattr tag[2]
DESCRIPTION
The setattr command changes some of the file status information.
attr resembles the iattr structure used in Linux kernel. It
specifies which status parameter is to be changed and to what
value. It is laid out as follows:
valid[4]
specifies which status information is to be changed. Possible
values are:
ATTR_MODE (1 << 0)
ATTR_UID (1 << 1)
ATTR_GID (1 << 2)
ATTR_SIZE (1 << 3)
ATTR_ATIME (1 << 4)
ATTR_MTIME (1 << 5)
ATTR_CTIME (1 << 5)
ATTR_ATIME_SET (1 << 7)
ATTR_MTIME_SET (1 << 8)
The last two bits represent whether the time information
is being sent by the client's user space. In the absense
of these bits the server always uses server's time.
mode[4]
File permission bits
uid[4]
Owner id of file
gid[4]
Group id of the file
size[8]
File size
atime_sec[8]
Time of last file access, seconds
atime_nsec[8]
Time of last file access, nanoseconds
mtime_sec[8]
Time of last file modification, seconds
mtime_nsec[8]
Time of last file modification, nanoseconds
Explanation of the patches:
--------------------------
*) The kernel just copies relevent contents of iattr structure to p9_iattr_dotl
structure and passes it down to the client. The only check it has is calling
inode_change_ok()
*) The p9_iattr_dotl structure does not have ctime and ia_file parameters because
I don't think these are needed in our case. The client user space can request
updating just ctime by calling chown(fd, -1, -1). This is handled on server
side without a need for putting ctime on the wire.
*) The server currently supports changing mode, time, ownership and size of the
file.
*) 9P RFC says "Either all the changes in wstat request happen, or none of them
does: if the request succeeds, all changes were made; if it fails, none were."
I have not done anything to implement this specifically because I don't see
a reason.
[jvrao@linux.vnet.ibm.com: Parts of code for handling chown(-1,-1)
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
2010-06-17 16:48:47 +04:00
|
|
|
if ((credp->fc_uid == -1 && credp->fc_gid == -1) ||
|
2011-10-25 10:40:39 +04:00
|
|
|
(fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
|
|
|
|
(fs_ctx->export_flags & V9FS_SM_NONE)) {
|
2017-02-27 01:44:37 +03:00
|
|
|
ret = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
|
|
|
|
AT_SYMLINK_NOFOLLOW);
|
2011-10-13 11:51:00 +04:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
|
2017-02-27 01:44:37 +03:00
|
|
|
ret = local_set_xattrat(dirfd, name, credp);
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2017-02-27 01:44:37 +03:00
|
|
|
ret = local_set_mapped_file_attrat(dirfd, name, credp);
|
2010-06-15 00:34:43 +04:00
|
|
|
}
|
2017-02-27 01:44:37 +03:00
|
|
|
|
|
|
|
close_preserve_errno(dirfd);
|
|
|
|
out:
|
|
|
|
g_free(name);
|
|
|
|
g_free(dirpath);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
return ret;
|
2010-04-29 16:15:00 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_utimensat(FsContext *s, V9fsPath *fs_path,
|
2010-11-24 05:38:10 +03:00
|
|
|
const struct timespec *buf)
|
2010-04-29 16:15:00 +04:00
|
|
|
{
|
2017-02-27 01:43:17 +03:00
|
|
|
char *dirpath = g_path_get_dirname(fs_path->data);
|
|
|
|
char *name = g_path_get_basename(fs_path->data);
|
|
|
|
int dirfd, ret = -1;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:43:17 +03:00
|
|
|
dirfd = local_opendir_nofollow(s, dirpath);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_utimensat(dirfd, name, buf, AT_SYMLINK_NOFOLLOW);
|
2017-02-27 01:43:17 +03:00
|
|
|
close_preserve_errno(dirfd);
|
|
|
|
out:
|
|
|
|
g_free(dirpath);
|
|
|
|
g_free(name);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
return ret;
|
2010-04-29 16:15:00 +04:00
|
|
|
}
|
|
|
|
|
2017-02-27 01:43:00 +03:00
|
|
|
static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
|
|
|
|
int flags)
|
2010-04-29 16:15:01 +04:00
|
|
|
{
|
2020-01-20 17:11:39 +03:00
|
|
|
int ret;
|
2012-01-19 10:51:11 +04:00
|
|
|
|
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
2017-02-27 01:43:00 +03:00
|
|
|
int map_dirfd;
|
|
|
|
|
2017-05-25 11:30:13 +03:00
|
|
|
/* We need to remove the metadata as well:
|
|
|
|
* - the metadata directory if we're removing a directory
|
|
|
|
* - the metadata file in the parent's metadata directory
|
|
|
|
*
|
|
|
|
* If any of these are missing (ie, ENOENT) then we're probably
|
|
|
|
* trying to remove something that wasn't created in mapped-file
|
|
|
|
* mode. We just ignore the error.
|
|
|
|
*/
|
2017-02-27 01:43:00 +03:00
|
|
|
if (flags == AT_REMOVEDIR) {
|
|
|
|
int fd;
|
|
|
|
|
2017-03-06 19:34:01 +03:00
|
|
|
fd = openat_dir(dirfd, name);
|
2017-02-27 01:43:00 +03:00
|
|
|
if (fd == -1) {
|
2020-01-20 17:11:39 +03:00
|
|
|
return -1;
|
2017-02-27 01:43:00 +03:00
|
|
|
}
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
|
2017-02-27 01:43:00 +03:00
|
|
|
close_preserve_errno(fd);
|
|
|
|
if (ret < 0 && errno != ENOENT) {
|
2020-01-20 17:11:39 +03:00
|
|
|
return -1;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
}
|
2017-02-27 01:43:00 +03:00
|
|
|
map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
|
2017-05-25 11:30:13 +03:00
|
|
|
if (map_dirfd != -1) {
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_unlinkat(map_dirfd, name, 0);
|
2017-05-25 11:30:13 +03:00
|
|
|
close_preserve_errno(map_dirfd);
|
|
|
|
if (ret < 0 && errno != ENOENT) {
|
2020-01-20 17:11:39 +03:00
|
|
|
return -1;
|
2017-05-25 11:30:13 +03:00
|
|
|
}
|
|
|
|
} else if (errno != ENOENT) {
|
2020-01-20 17:11:39 +03:00
|
|
|
return -1;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
|
|
|
}
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
|
2022-12-19 13:20:07 +03:00
|
|
|
return qemu_unlinkat(dirfd, name, flags);
|
2017-02-27 01:43:00 +03:00
|
|
|
}
|
|
|
|
|
2010-04-29 16:15:01 +04:00
|
|
|
static int local_remove(FsContext *ctx, const char *path)
|
|
|
|
{
|
2012-01-19 10:51:11 +04:00
|
|
|
struct stat stbuf;
|
2017-02-27 01:43:08 +03:00
|
|
|
char *dirpath = g_path_get_dirname(path);
|
|
|
|
char *name = g_path_get_basename(path);
|
|
|
|
int flags = 0;
|
|
|
|
int dirfd;
|
|
|
|
int err = -1;
|
2012-01-19 10:51:11 +04:00
|
|
|
|
2017-02-27 01:43:08 +03:00
|
|
|
dirfd = local_opendir_nofollow(ctx, dirpath);
|
2017-03-06 19:34:01 +03:00
|
|
|
if (dirfd == -1) {
|
2017-02-27 01:43:08 +03:00
|
|
|
goto out;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
|
2022-12-19 13:20:07 +03:00
|
|
|
if (qemu_fstatat(dirfd, name, &stbuf, AT_SYMLINK_NOFOLLOW) < 0) {
|
2017-02-27 01:43:08 +03:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISDIR(stbuf.st_mode)) {
|
|
|
|
flags |= AT_REMOVEDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = local_unlinkat_common(ctx, dirfd, name, flags);
|
2012-01-19 10:51:11 +04:00
|
|
|
err_out:
|
2017-02-27 01:43:08 +03:00
|
|
|
close_preserve_errno(dirfd);
|
|
|
|
out:
|
|
|
|
g_free(name);
|
|
|
|
g_free(dirpath);
|
2012-01-19 10:51:11 +04:00
|
|
|
return err;
|
2010-04-29 16:15:01 +04:00
|
|
|
}
|
|
|
|
|
2011-12-04 21:05:28 +04:00
|
|
|
static int local_fsync(FsContext *ctx, int fid_type,
|
|
|
|
V9fsFidOpenState *fs, int datasync)
|
2010-04-29 16:15:00 +04:00
|
|
|
{
|
2011-12-04 21:05:28 +04:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (fid_type == P9_FID_DIR) {
|
2016-06-06 12:52:34 +03:00
|
|
|
fd = dirfd(fs->dir.stream);
|
2011-12-04 21:05:28 +04:00
|
|
|
} else {
|
|
|
|
fd = fs->fd;
|
|
|
|
}
|
|
|
|
|
2010-10-22 21:08:45 +04:00
|
|
|
if (datasync) {
|
2011-12-04 21:05:28 +04:00
|
|
|
return qemu_fdatasync(fd);
|
2010-10-22 21:08:45 +04:00
|
|
|
} else {
|
2011-12-04 21:05:28 +04:00
|
|
|
return fsync(fd);
|
2010-10-22 21:08:45 +04:00
|
|
|
}
|
2010-04-29 16:15:00 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
|
2010-05-10 10:41:03 +04:00
|
|
|
{
|
2017-02-27 01:43:25 +03:00
|
|
|
int fd, ret;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:43:25 +03:00
|
|
|
fd = local_open_nofollow(s, fs_path->data, O_RDONLY, 0);
|
2017-03-06 19:34:01 +03:00
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-27 01:43:25 +03:00
|
|
|
ret = fstatfs(fd, stbuf);
|
|
|
|
close_preserve_errno(fd);
|
hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation
When path is truncated by PATH_MAX limitation, it causes QEMU to access
incorrect file. So use original full path instead of PATH_MAX within
9pfs (need check/process ENOMEM for related memory allocation).
The related test:
- Environments (for qemu-devel):
- Host is under fedora17 desktop with ext4fs:
qemu-system-x86_64 -hda test.img -m 1024 \
-net nic,vlan=4,model=virtio,macaddr=00:16:35:AF:94:04 \
-net tap,vlan=4,ifname=tap4,script=no,downscript=no \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
-fsdev local,security_model=passthrough,id=fsdev0,\
path=/upstream/vm/data/share/1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111111111\
1111111111111111111111111111111111111111111111111111222222222222\
2222222222222222222222222222222222222222222222222222222222222222\
2222222222222222222222222222222222233333333333333333333333333333\
3333333333333333333333333333333333
- Guest is ubuntu12 server with 9pfs.
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /share
- Limitations:
full path limitation is PATH_MAX (4096B include nul) under Linux.
file/dir node name maximized length is 256 (include nul) under ext4.
- Special test:
Under host, modify the file: "/upstream/vm/data/share/1234567890abcdefg\
hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890acdefghijklmno\
pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/111111111111111111111\
111111111111111111111111111111111111111111111111111111111122222222222\
222222222222222222222222222222222222222222222222222222222222222222222\
222222222222222222222222222222233333333333333333333333333333333333333\
3333333333333333333333333/4444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444444444444444444444444444444444\
444444444444444444444444444444444444444/55555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
555555555555555555555555555555555555555555555555555555555555555555555\
55555555/666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666666666666666666666666666666666666666666666666666\
666666666666666666666/77777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777777777777777777777777777777777777777\
77777777777777777777777777777777777777777777777777777777777/888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888888888888888888888888888888888888888888888888888888888888888\
888888888/99999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999/000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000/aaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccc/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
dddddddddddddddddddddd/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/fffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\
ggggggggggggggggggggggg/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/jjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj/ppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\
ppppppppppppppppppppppppppppppppppppppp/test1234567890file.log"
(need enter dir firstly, then modify file, or can not open it).
Under guest, still allow modify "test1234567890file.log" (will generate
"test123456" file with contents).
After apply this patch, can not open "test1234567890file.log" under guest
(permission denied).
- Common test:
All are still OK after apply this path.
"mkdir -p", "create/open file/dir", "modify file/dir", "rm file/dir".
change various mount point paths under host and/or guest.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2014-03-01 21:36:19 +04:00
|
|
|
return ret;
|
2010-05-10 10:41:03 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static ssize_t local_lgetxattr(FsContext *ctx, V9fsPath *fs_path,
|
2010-09-02 09:39:06 +04:00
|
|
|
const char *name, void *value, size_t size)
|
|
|
|
{
|
2011-09-09 13:44:18 +04:00
|
|
|
char *path = fs_path->data;
|
|
|
|
|
2010-10-18 13:58:16 +04:00
|
|
|
return v9fs_get_xattr(ctx, path, name, value, size);
|
2010-09-02 09:39:06 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static ssize_t local_llistxattr(FsContext *ctx, V9fsPath *fs_path,
|
2010-09-02 09:39:06 +04:00
|
|
|
void *value, size_t size)
|
|
|
|
{
|
2011-09-09 13:44:18 +04:00
|
|
|
char *path = fs_path->data;
|
|
|
|
|
2010-10-18 13:58:16 +04:00
|
|
|
return v9fs_list_xattr(ctx, path, value, size);
|
2010-09-02 09:39:06 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name,
|
2010-09-02 09:39:07 +04:00
|
|
|
void *value, size_t size, int flags)
|
|
|
|
{
|
2011-09-09 13:44:18 +04:00
|
|
|
char *path = fs_path->data;
|
|
|
|
|
2010-10-18 13:58:16 +04:00
|
|
|
return v9fs_set_xattr(ctx, path, name, value, size, flags);
|
2010-09-02 09:39:07 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_lremovexattr(FsContext *ctx, V9fsPath *fs_path,
|
|
|
|
const char *name)
|
2010-08-26 09:45:23 +04:00
|
|
|
{
|
2011-09-09 13:44:18 +04:00
|
|
|
char *path = fs_path->data;
|
|
|
|
|
2010-10-18 13:58:16 +04:00
|
|
|
return v9fs_remove_xattr(ctx, path, name);
|
2010-08-26 09:45:23 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path,
|
|
|
|
const char *name, V9fsPath *target)
|
|
|
|
{
|
2017-05-05 15:48:08 +03:00
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
local_is_mapped_file_metadata(ctx, name)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
if (dir_path) {
|
2017-05-25 11:30:14 +03:00
|
|
|
if (!strcmp(name, ".")) {
|
|
|
|
/* "." relative to "foo/bar" is "foo/bar" */
|
|
|
|
v9fs_path_copy(target, dir_path);
|
|
|
|
} else if (!strcmp(name, "..")) {
|
|
|
|
if (!strcmp(dir_path->data, ".")) {
|
|
|
|
/* ".." relative to the root is "." */
|
|
|
|
v9fs_path_sprintf(target, ".");
|
|
|
|
} else {
|
|
|
|
char *tmp = g_path_get_dirname(dir_path->data);
|
|
|
|
/* Symbolic links are resolved by the client. We can assume
|
|
|
|
* that ".." relative to "foo/bar" is equivalent to "foo"
|
|
|
|
*/
|
|
|
|
v9fs_path_sprintf(target, "%s", tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(!strchr(name, '/'));
|
|
|
|
v9fs_path_sprintf(target, "%s/%s", dir_path->data, name);
|
|
|
|
}
|
|
|
|
} else if (!strcmp(name, "/") || !strcmp(name, ".") ||
|
|
|
|
!strcmp(name, "..")) {
|
|
|
|
/* This is the root fid */
|
|
|
|
v9fs_path_sprintf(target, ".");
|
2017-04-17 11:53:23 +03:00
|
|
|
} else {
|
2017-05-25 11:30:14 +03:00
|
|
|
assert(!strchr(name, '/'));
|
|
|
|
v9fs_path_sprintf(target, "./%s", name);
|
2011-09-09 13:44:18 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int local_renameat(FsContext *ctx, V9fsPath *olddir,
|
|
|
|
const char *old_name, V9fsPath *newdir,
|
|
|
|
const char *new_name)
|
|
|
|
{
|
|
|
|
int ret;
|
2017-02-27 01:43:55 +03:00
|
|
|
int odirfd, ndirfd;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
(local_is_mapped_file_metadata(ctx, old_name) ||
|
|
|
|
local_is_mapped_file_metadata(ctx, new_name))) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:43:55 +03:00
|
|
|
odirfd = local_opendir_nofollow(ctx, olddir->data);
|
|
|
|
if (odirfd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:43:55 +03:00
|
|
|
ndirfd = local_opendir_nofollow(ctx, newdir->data);
|
|
|
|
if (ndirfd == -1) {
|
|
|
|
close_preserve_errno(odirfd);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_renameat(odirfd, old_name, ndirfd, new_name);
|
2017-02-27 01:43:55 +03:00
|
|
|
if (ret < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:43:55 +03:00
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
|
|
|
int omap_dirfd, nmap_dirfd;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_mkdirat(ndirfd, VIRTFS_META_DIR, 0700);
|
2017-02-27 01:43:55 +03:00
|
|
|
if (ret < 0 && errno != EEXIST) {
|
|
|
|
goto err_undo_rename;
|
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:44:11 +03:00
|
|
|
omap_dirfd = openat_dir(odirfd, VIRTFS_META_DIR);
|
2017-02-27 01:43:55 +03:00
|
|
|
if (omap_dirfd == -1) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:11 +03:00
|
|
|
nmap_dirfd = openat_dir(ndirfd, VIRTFS_META_DIR);
|
2017-02-27 01:43:55 +03:00
|
|
|
if (nmap_dirfd == -1) {
|
|
|
|
close_preserve_errno(omap_dirfd);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rename the .virtfs_metadata files */
|
2022-12-19 13:20:07 +03:00
|
|
|
ret = qemu_renameat(omap_dirfd, old_name, nmap_dirfd, new_name);
|
2017-02-27 01:43:55 +03:00
|
|
|
close_preserve_errno(nmap_dirfd);
|
|
|
|
close_preserve_errno(omap_dirfd);
|
|
|
|
if (ret < 0 && errno != ENOENT) {
|
|
|
|
goto err_undo_rename;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err:
|
|
|
|
ret = -1;
|
|
|
|
err_undo_rename:
|
|
|
|
renameat_preserve_errno(ndirfd, new_name, odirfd, old_name);
|
|
|
|
out:
|
|
|
|
close_preserve_errno(ndirfd);
|
|
|
|
close_preserve_errno(odirfd);
|
2011-09-09 13:44:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:44:03 +03:00
|
|
|
static void v9fs_path_init_dirname(V9fsPath *path, const char *str)
|
|
|
|
{
|
|
|
|
path->data = g_path_get_dirname(str);
|
|
|
|
path->size = strlen(path->data) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int local_rename(FsContext *ctx, const char *oldpath,
|
|
|
|
const char *newpath)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char *oname = g_path_get_basename(oldpath);
|
|
|
|
char *nname = g_path_get_basename(newpath);
|
|
|
|
V9fsPath olddir, newdir;
|
|
|
|
|
|
|
|
v9fs_path_init_dirname(&olddir, oldpath);
|
|
|
|
v9fs_path_init_dirname(&newdir, newpath);
|
|
|
|
|
|
|
|
err = local_renameat(ctx, &olddir, oname, &newdir, nname);
|
|
|
|
|
|
|
|
v9fs_path_free(&newdir);
|
|
|
|
v9fs_path_free(&olddir);
|
|
|
|
g_free(nname);
|
|
|
|
g_free(oname);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-09-09 13:44:18 +04:00
|
|
|
static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
|
|
|
|
const char *name, int flags)
|
|
|
|
{
|
|
|
|
int ret;
|
2017-02-27 01:43:00 +03:00
|
|
|
int dirfd;
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-05-05 15:48:08 +03:00
|
|
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
|
|
|
|
local_is_mapped_file_metadata(ctx, name)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:43:00 +03:00
|
|
|
dirfd = local_opendir_nofollow(ctx, dir->data);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
return -1;
|
2012-01-19 10:51:11 +04:00
|
|
|
}
|
2011-09-09 13:44:18 +04:00
|
|
|
|
2017-02-27 01:43:00 +03:00
|
|
|
ret = local_unlinkat_common(ctx, dirfd, name, flags);
|
|
|
|
close_preserve_errno(dirfd);
|
2011-09-09 13:44:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2010-08-26 09:45:23 +04:00
|
|
|
|
2018-06-07 13:17:22 +03:00
|
|
|
#ifdef FS_IOC_GETVERSION
|
2011-10-12 17:41:25 +04:00
|
|
|
static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
|
|
|
|
mode_t st_mode, uint64_t *st_gen)
|
|
|
|
{
|
2014-01-28 19:08:24 +04:00
|
|
|
int err;
|
2011-10-25 10:40:40 +04:00
|
|
|
V9fsFidOpenState fid_open;
|
|
|
|
|
2011-10-12 17:41:25 +04:00
|
|
|
/*
|
|
|
|
* Do not try to open special files like device nodes, fifos etc
|
|
|
|
* We can get fd for regular files and directories only
|
|
|
|
*/
|
|
|
|
if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
|
2014-01-28 19:08:26 +04:00
|
|
|
errno = ENOTTY;
|
|
|
|
return -1;
|
2011-10-12 17:41:25 +04:00
|
|
|
}
|
2011-10-25 10:40:40 +04:00
|
|
|
err = local_open(ctx, path, O_RDONLY, &fid_open);
|
|
|
|
if (err < 0) {
|
|
|
|
return err;
|
2011-10-12 17:41:25 +04:00
|
|
|
}
|
2011-10-25 10:40:40 +04:00
|
|
|
err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
|
|
|
|
local_close(ctx, &fid_open);
|
2014-01-28 19:08:24 +04:00
|
|
|
return err;
|
2011-10-12 17:41:25 +04:00
|
|
|
}
|
2018-06-07 13:17:22 +03:00
|
|
|
#endif
|
2011-10-12 17:41:25 +04:00
|
|
|
|
2018-06-07 13:17:22 +03:00
|
|
|
static int local_ioc_getversion_init(FsContext *ctx, LocalData *data, Error **errp)
|
2011-08-02 10:05:54 +04:00
|
|
|
{
|
2018-06-07 13:17:22 +03:00
|
|
|
#ifdef FS_IOC_GETVERSION
|
2011-10-12 17:41:25 +04:00
|
|
|
struct statfs stbuf;
|
2017-02-27 01:42:10 +03:00
|
|
|
|
2017-02-27 01:41:48 +03:00
|
|
|
/*
|
2023-07-14 14:13:50 +03:00
|
|
|
* use ioc_getversion only if the ioctl is defined
|
2017-02-27 01:41:48 +03:00
|
|
|
*/
|
2017-02-27 01:42:10 +03:00
|
|
|
if (fstatfs(data->mountfd, &stbuf) < 0) {
|
2018-06-07 13:17:21 +03:00
|
|
|
error_setg_errno(errp, errno,
|
2018-06-07 13:17:22 +03:00
|
|
|
"failed to stat file system at '%s'", ctx->fs_root);
|
|
|
|
return -1;
|
2017-02-27 01:41:48 +03:00
|
|
|
}
|
|
|
|
switch (stbuf.f_type) {
|
|
|
|
case EXT2_SUPER_MAGIC:
|
|
|
|
case BTRFS_SUPER_MAGIC:
|
|
|
|
case REISERFS_SUPER_MAGIC:
|
|
|
|
case XFS_SUPER_MAGIC:
|
|
|
|
ctx->exops.get_st_gen = local_ioc_getversion;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2018-06-07 13:17:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int local_init(FsContext *ctx, Error **errp)
|
|
|
|
{
|
|
|
|
LocalData *data = g_malloc(sizeof(*data));
|
|
|
|
|
|
|
|
data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY);
|
|
|
|
if (data->mountfd == -1) {
|
|
|
|
error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (local_ioc_getversion_init(ctx, data, errp) < 0) {
|
|
|
|
close(data->mountfd);
|
|
|
|
goto err;
|
|
|
|
}
|
2011-10-12 17:41:25 +04:00
|
|
|
|
2012-01-19 10:51:11 +04:00
|
|
|
if (ctx->export_flags & V9FS_SM_PASSTHROUGH) {
|
|
|
|
ctx->xops = passthrough_xattr_ops;
|
|
|
|
} else if (ctx->export_flags & V9FS_SM_MAPPED) {
|
|
|
|
ctx->xops = mapped_xattr_ops;
|
|
|
|
} else if (ctx->export_flags & V9FS_SM_NONE) {
|
|
|
|
ctx->xops = none_xattr_ops;
|
|
|
|
} else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
|
|
|
/*
|
|
|
|
* xattr operation for mapped-file and passthrough
|
|
|
|
* remain same.
|
|
|
|
*/
|
|
|
|
ctx->xops = passthrough_xattr_ops;
|
|
|
|
}
|
2011-10-12 19:29:18 +04:00
|
|
|
ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT;
|
2017-02-27 01:41:48 +03:00
|
|
|
|
2017-02-27 01:42:10 +03:00
|
|
|
ctx->private = data;
|
2017-02-27 01:41:48 +03:00
|
|
|
return 0;
|
2017-02-27 01:42:10 +03:00
|
|
|
|
|
|
|
err:
|
|
|
|
g_free(data);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void local_cleanup(FsContext *ctx)
|
|
|
|
{
|
|
|
|
LocalData *data = ctx->private;
|
|
|
|
|
2019-10-10 12:36:04 +03:00
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:42:10 +03:00
|
|
|
close(data->mountfd);
|
|
|
|
g_free(data);
|
2011-08-02 10:05:54 +04:00
|
|
|
}
|
|
|
|
|
2019-12-05 20:46:22 +03:00
|
|
|
static void error_append_security_model_hint(Error *const *errp)
|
2018-01-08 13:18:23 +03:00
|
|
|
{
|
|
|
|
error_append_hint(errp, "Valid options are: security_model="
|
|
|
|
"[passthrough|mapped-xattr|mapped-file|none]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
|
2011-12-14 12:18:59 +04:00
|
|
|
{
|
2020-07-07 19:50:35 +03:00
|
|
|
ERRP_GUARD();
|
2011-12-14 12:18:59 +04:00
|
|
|
const char *sec_model = qemu_opt_get(opts, "security_model");
|
|
|
|
const char *path = qemu_opt_get(opts, "path");
|
2019-10-10 12:36:05 +03:00
|
|
|
const char *multidevs = qemu_opt_get(opts, "multidevs");
|
2011-12-14 12:18:59 +04:00
|
|
|
|
|
|
|
if (!sec_model) {
|
2018-01-08 13:18:23 +03:00
|
|
|
error_setg(errp, "security_model property not set");
|
|
|
|
error_append_security_model_hint(errp);
|
2011-12-14 12:18:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(sec_model, "passthrough")) {
|
|
|
|
fse->export_flags |= V9FS_SM_PASSTHROUGH;
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strcmp(sec_model, "mapped") ||
|
|
|
|
!strcmp(sec_model, "mapped-xattr")) {
|
2011-12-14 12:18:59 +04:00
|
|
|
fse->export_flags |= V9FS_SM_MAPPED;
|
|
|
|
} else if (!strcmp(sec_model, "none")) {
|
|
|
|
fse->export_flags |= V9FS_SM_NONE;
|
2012-01-19 10:51:11 +04:00
|
|
|
} else if (!strcmp(sec_model, "mapped-file")) {
|
|
|
|
fse->export_flags |= V9FS_SM_MAPPED_FILE;
|
2011-12-14 12:18:59 +04:00
|
|
|
} else {
|
2018-01-08 13:18:23 +03:00
|
|
|
error_setg(errp, "invalid security_model property '%s'", sec_model);
|
|
|
|
error_append_security_model_hint(errp);
|
2011-12-14 12:18:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-10-10 12:36:05 +03:00
|
|
|
if (multidevs) {
|
|
|
|
if (!strcmp(multidevs, "remap")) {
|
|
|
|
fse->export_flags &= ~V9FS_FORBID_MULTIDEVS;
|
|
|
|
fse->export_flags |= V9FS_REMAP_INODES;
|
|
|
|
} else if (!strcmp(multidevs, "forbid")) {
|
|
|
|
fse->export_flags &= ~V9FS_REMAP_INODES;
|
|
|
|
fse->export_flags |= V9FS_FORBID_MULTIDEVS;
|
|
|
|
} else if (!strcmp(multidevs, "warn")) {
|
|
|
|
fse->export_flags &= ~V9FS_FORBID_MULTIDEVS;
|
|
|
|
fse->export_flags &= ~V9FS_REMAP_INODES;
|
|
|
|
} else {
|
2020-07-07 19:50:35 +03:00
|
|
|
error_setg(errp, "invalid multidevs property '%s'",
|
2019-10-10 12:36:05 +03:00
|
|
|
multidevs);
|
2020-07-07 19:50:35 +03:00
|
|
|
error_append_hint(errp, "Valid options are: multidevs="
|
2019-10-10 12:36:05 +03:00
|
|
|
"[remap|forbid|warn]\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-14 12:18:59 +04:00
|
|
|
if (!path) {
|
2018-01-08 13:18:23 +03:00
|
|
|
error_setg(errp, "path property not set");
|
2011-12-14 12:18:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2017-02-28 12:31:46 +03:00
|
|
|
|
2020-07-07 19:50:35 +03:00
|
|
|
if (fsdev_throttle_parse_opts(opts, &fse->fst, errp)) {
|
|
|
|
error_prepend(errp, "invalid throttle configuration: ");
|
2017-02-28 12:31:46 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-06-29 16:11:50 +03:00
|
|
|
if (fse->export_flags & V9FS_SM_MAPPED ||
|
|
|
|
fse->export_flags & V9FS_SM_MAPPED_FILE) {
|
|
|
|
fse->fmode =
|
|
|
|
qemu_opt_get_number(opts, "fmode", SM_LOCAL_MODE_BITS) & 0777;
|
|
|
|
fse->dmode =
|
|
|
|
qemu_opt_get_number(opts, "dmode", SM_LOCAL_DIR_MODE_BITS) & 0777;
|
|
|
|
} else {
|
|
|
|
if (qemu_opt_find(opts, "fmode")) {
|
2018-01-08 13:18:23 +03:00
|
|
|
error_setg(errp, "fmode is only valid for mapped security modes");
|
2017-06-29 16:11:50 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (qemu_opt_find(opts, "dmode")) {
|
2018-01-08 13:18:23 +03:00
|
|
|
error_setg(errp, "dmode is only valid for mapped security modes");
|
2017-06-29 16:11:50 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-14 12:18:59 +04:00
|
|
|
fse->path = g_strdup(path);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-29 16:14:44 +04:00
|
|
|
FileOperations local_ops = {
|
2011-12-14 12:18:59 +04:00
|
|
|
.parse_opts = local_parse_opts,
|
2011-08-02 10:05:54 +04:00
|
|
|
.init = local_init,
|
2017-02-27 01:42:10 +03:00
|
|
|
.cleanup = local_cleanup,
|
2010-04-29 16:14:47 +04:00
|
|
|
.lstat = local_lstat,
|
|
|
|
.readlink = local_readlink,
|
|
|
|
.close = local_close,
|
|
|
|
.closedir = local_closedir,
|
2010-04-29 16:14:55 +04:00
|
|
|
.open = local_open,
|
|
|
|
.opendir = local_opendir,
|
2010-04-29 16:14:56 +04:00
|
|
|
.rewinddir = local_rewinddir,
|
|
|
|
.telldir = local_telldir,
|
2016-06-06 12:52:34 +03:00
|
|
|
.readdir = local_readdir,
|
2010-04-29 16:14:56 +04:00
|
|
|
.seekdir = local_seekdir,
|
2010-10-08 10:00:16 +04:00
|
|
|
.preadv = local_preadv,
|
|
|
|
.pwritev = local_pwritev,
|
2010-04-29 16:14:59 +04:00
|
|
|
.chmod = local_chmod,
|
|
|
|
.mknod = local_mknod,
|
|
|
|
.mkdir = local_mkdir,
|
|
|
|
.fstat = local_fstat,
|
|
|
|
.open2 = local_open2,
|
|
|
|
.symlink = local_symlink,
|
|
|
|
.link = local_link,
|
2010-04-29 16:15:00 +04:00
|
|
|
.truncate = local_truncate,
|
|
|
|
.rename = local_rename,
|
|
|
|
.chown = local_chown,
|
2010-06-09 17:44:38 +04:00
|
|
|
.utimensat = local_utimensat,
|
2010-04-29 16:15:01 +04:00
|
|
|
.remove = local_remove,
|
2010-04-29 16:15:00 +04:00
|
|
|
.fsync = local_fsync,
|
2010-05-10 10:41:03 +04:00
|
|
|
.statfs = local_statfs,
|
2010-09-02 09:39:06 +04:00
|
|
|
.lgetxattr = local_lgetxattr,
|
|
|
|
.llistxattr = local_llistxattr,
|
2010-09-02 09:39:07 +04:00
|
|
|
.lsetxattr = local_lsetxattr,
|
2010-08-26 09:45:23 +04:00
|
|
|
.lremovexattr = local_lremovexattr,
|
2011-09-09 13:44:18 +04:00
|
|
|
.name_to_path = local_name_to_path,
|
|
|
|
.renameat = local_renameat,
|
|
|
|
.unlinkat = local_unlinkat,
|
2010-04-29 16:14:44 +04:00
|
|
|
};
|