Anthony Liguori | 9f10751 | 2010-04-29 17:44:44 +0530 | [diff] [blame] | 1 | /* |
Wei Liu | f00d4f5 | 2015-11-18 18:05:29 +0000 | [diff] [blame] | 2 | * 9p Posix callback |
Anthony Liguori | 9f10751 | 2010-04-29 17:44:44 +0530 | [diff] [blame] | 3 | * |
| 4 | * Copyright IBM, Corp. 2010 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
| 12 | */ |
Stefan Weil | 873c321 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 13 | |
Peter Maydell | fbc0412 | 2016-01-26 18:17:10 +0000 | [diff] [blame] | 14 | #include "qemu/osdep.h" |
Wei Liu | ebe74f8 | 2016-01-07 18:18:02 +0000 | [diff] [blame] | 15 | #include "9p.h" |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 16 | #include "9p-local.h" |
Wei Liu | 267ae09 | 2015-11-18 18:31:52 +0000 | [diff] [blame] | 17 | #include "9p-xattr.h" |
Greg Kurz | 0e35a37 | 2017-02-26 23:42:10 +0100 | [diff] [blame] | 18 | #include "9p-util.h" |
Stefan Weil | 69b1521 | 2014-05-02 22:22:32 +0200 | [diff] [blame] | 19 | #include "fsdev/qemu-fsdev.h" /* local_ops */ |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 20 | #include <arpa/inet.h> |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 21 | #include <pwd.h> |
| 22 | #include <grp.h> |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 23 | #include <sys/socket.h> |
| 24 | #include <sys/un.h> |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 25 | #include "qemu/xattr.h" |
Veronia Bahaa | f348b6d | 2016-03-20 19:16:19 +0200 | [diff] [blame] | 26 | #include "qemu/cutils.h" |
Greg Kurz | 63325b1 | 2016-01-22 15:12:17 +0100 | [diff] [blame] | 27 | #include "qemu/error-report.h" |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 28 | #include <libgen.h> |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 29 | #include <linux/fs.h> |
| 30 | #ifdef CONFIG_LINUX_MAGIC_H |
| 31 | #include <linux/magic.h> |
| 32 | #endif |
| 33 | #include <sys/ioctl.h> |
| 34 | |
| 35 | #ifndef XFS_SUPER_MAGIC |
| 36 | #define XFS_SUPER_MAGIC 0x58465342 |
| 37 | #endif |
| 38 | #ifndef EXT2_SUPER_MAGIC |
| 39 | #define EXT2_SUPER_MAGIC 0xEF53 |
| 40 | #endif |
| 41 | #ifndef REISERFS_SUPER_MAGIC |
| 42 | #define REISERFS_SUPER_MAGIC 0x52654973 |
| 43 | #endif |
| 44 | #ifndef BTRFS_SUPER_MAGIC |
| 45 | #define BTRFS_SUPER_MAGIC 0x9123683E |
| 46 | #endif |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 47 | |
Greg Kurz | 0e35a37 | 2017-02-26 23:42:10 +0100 | [diff] [blame] | 48 | typedef struct { |
| 49 | int mountfd; |
| 50 | } LocalData; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 51 | |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 52 | int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, |
| 53 | mode_t mode) |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 54 | { |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 55 | LocalData *data = fs_ctx->private; |
| 56 | |
| 57 | /* All paths are relative to the path data->mountfd points to */ |
| 58 | while (*path == '/') { |
| 59 | path++; |
Michael Tokarev | 1b6f85e | 2015-03-12 09:52:30 +0300 | [diff] [blame] | 60 | } |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 61 | |
| 62 | return relative_openat_nofollow(data->mountfd, path, flags, mode); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 63 | } |
| 64 | |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 65 | int local_opendir_nofollow(FsContext *fs_ctx, const char *path) |
| 66 | { |
| 67 | return local_open_nofollow(fs_ctx, path, O_DIRECTORY | O_RDONLY, 0); |
| 68 | } |
| 69 | |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 70 | static void renameat_preserve_errno(int odirfd, const char *opath, int ndirfd, |
| 71 | const char *npath) |
| 72 | { |
| 73 | int serrno = errno; |
| 74 | renameat(odirfd, opath, ndirfd, npath); |
| 75 | errno = serrno; |
| 76 | } |
| 77 | |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 78 | static void unlinkat_preserve_errno(int dirfd, const char *path, int flags) |
| 79 | { |
| 80 | int serrno = errno; |
| 81 | unlinkat(dirfd, path, flags); |
| 82 | errno = serrno; |
| 83 | } |
| 84 | |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 85 | #define VIRTFS_META_DIR ".virtfs_metadata" |
| 86 | |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 87 | static FILE *local_fopenat(int dirfd, const char *name, const char *mode) |
Aneesh Kumar K.V | 0ceb092 | 2013-05-20 19:43:15 +0530 | [diff] [blame] | 88 | { |
| 89 | int fd, o_mode = 0; |
| 90 | FILE *fp; |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 91 | int flags; |
Aneesh Kumar K.V | 0ceb092 | 2013-05-20 19:43:15 +0530 | [diff] [blame] | 92 | /* |
| 93 | * only supports two modes |
| 94 | */ |
| 95 | if (mode[0] == 'r') { |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 96 | flags = O_RDONLY; |
Aneesh Kumar K.V | 0ceb092 | 2013-05-20 19:43:15 +0530 | [diff] [blame] | 97 | } else if (mode[0] == 'w') { |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 98 | flags = O_WRONLY | O_TRUNC | O_CREAT; |
Aneesh Kumar K.V | 0ceb092 | 2013-05-20 19:43:15 +0530 | [diff] [blame] | 99 | o_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; |
| 100 | } else { |
| 101 | return NULL; |
| 102 | } |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 103 | fd = openat_file(dirfd, name, flags, o_mode); |
Aneesh Kumar K.V | 0ceb092 | 2013-05-20 19:43:15 +0530 | [diff] [blame] | 104 | if (fd == -1) { |
| 105 | return NULL; |
| 106 | } |
| 107 | fp = fdopen(fd, mode); |
| 108 | if (!fp) { |
| 109 | close(fd); |
| 110 | } |
| 111 | return fp; |
| 112 | } |
| 113 | |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 114 | #define ATTR_MAX 100 |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 115 | static void local_mapped_file_attr(int dirfd, const char *name, |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 116 | struct stat *stbuf) |
| 117 | { |
| 118 | FILE *fp; |
| 119 | char buf[ATTR_MAX]; |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 120 | int map_dirfd; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 121 | |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 122 | map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR); |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 123 | if (map_dirfd == -1) { |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | fp = local_fopenat(map_dirfd, name, "r"); |
| 128 | close_preserve_errno(map_dirfd); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 129 | if (!fp) { |
| 130 | return; |
| 131 | } |
| 132 | memset(buf, 0, ATTR_MAX); |
| 133 | while (fgets(buf, ATTR_MAX, fp)) { |
| 134 | if (!strncmp(buf, "virtfs.uid", 10)) { |
| 135 | stbuf->st_uid = atoi(buf+11); |
| 136 | } else if (!strncmp(buf, "virtfs.gid", 10)) { |
| 137 | stbuf->st_gid = atoi(buf+11); |
| 138 | } else if (!strncmp(buf, "virtfs.mode", 11)) { |
| 139 | stbuf->st_mode = atoi(buf+12); |
| 140 | } else if (!strncmp(buf, "virtfs.rdev", 11)) { |
| 141 | stbuf->st_rdev = atoi(buf+12); |
| 142 | } |
| 143 | memset(buf, 0, ATTR_MAX); |
| 144 | } |
| 145 | fclose(fp); |
| 146 | } |
| 147 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 148 | static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 149 | { |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 150 | int err = -1; |
| 151 | char *dirpath = g_path_get_dirname(fs_path->data); |
| 152 | char *name = g_path_get_basename(fs_path->data); |
| 153 | int dirfd; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 154 | |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 155 | dirfd = local_opendir_nofollow(fs_ctx, dirpath); |
| 156 | if (dirfd == -1) { |
| 157 | goto out; |
| 158 | } |
| 159 | |
| 160 | err = fstatat(dirfd, name, stbuf, AT_SYMLINK_NOFOLLOW); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 161 | if (err) { |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 162 | goto err_out; |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 163 | } |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 164 | if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 165 | /* Actual credentials are part of extended attrs */ |
| 166 | uid_t tmp_uid; |
| 167 | gid_t tmp_gid; |
| 168 | mode_t tmp_mode; |
| 169 | dev_t tmp_dev; |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 170 | |
| 171 | if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.uid", &tmp_uid, |
| 172 | sizeof(uid_t)) > 0) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 173 | stbuf->st_uid = le32_to_cpu(tmp_uid); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 174 | } |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 175 | if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.gid", &tmp_gid, |
| 176 | sizeof(gid_t)) > 0) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 177 | stbuf->st_gid = le32_to_cpu(tmp_gid); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 178 | } |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 179 | if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.mode", &tmp_mode, |
| 180 | sizeof(mode_t)) > 0) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 181 | stbuf->st_mode = le32_to_cpu(tmp_mode); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 182 | } |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 183 | if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.rdev", &tmp_dev, |
| 184 | sizeof(dev_t)) > 0) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 185 | stbuf->st_rdev = le64_to_cpu(tmp_dev); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 186 | } |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 187 | } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 188 | local_mapped_file_attr(dirfd, name, stbuf); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 189 | } |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 190 | |
| 191 | err_out: |
Greg Kurz | f9aef99 | 2017-02-26 23:43:48 +0100 | [diff] [blame] | 192 | close_preserve_errno(dirfd); |
| 193 | out: |
| 194 | g_free(name); |
| 195 | g_free(dirpath); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 196 | return err; |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 197 | } |
| 198 | |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 199 | static int local_set_mapped_file_attrat(int dirfd, const char *name, |
| 200 | FsCred *credp) |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 201 | { |
| 202 | FILE *fp; |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 203 | int ret; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 204 | char buf[ATTR_MAX]; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 205 | int uid = -1, gid = -1, mode = -1, rdev = -1; |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 206 | int map_dirfd; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 207 | |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 208 | ret = mkdirat(dirfd, VIRTFS_META_DIR, 0700); |
| 209 | if (ret < 0 && errno != EEXIST) { |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR); |
| 214 | if (map_dirfd == -1) { |
| 215 | return -1; |
| 216 | } |
| 217 | |
| 218 | fp = local_fopenat(map_dirfd, name, "r"); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 219 | if (!fp) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 220 | if (errno == ENOENT) { |
| 221 | goto update_map_file; |
| 222 | } else { |
| 223 | close_preserve_errno(map_dirfd); |
| 224 | return -1; |
| 225 | } |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 226 | } |
| 227 | memset(buf, 0, ATTR_MAX); |
| 228 | while (fgets(buf, ATTR_MAX, fp)) { |
| 229 | if (!strncmp(buf, "virtfs.uid", 10)) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 230 | uid = atoi(buf + 11); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 231 | } else if (!strncmp(buf, "virtfs.gid", 10)) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 232 | gid = atoi(buf + 11); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 233 | } else if (!strncmp(buf, "virtfs.mode", 11)) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 234 | mode = atoi(buf + 12); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 235 | } else if (!strncmp(buf, "virtfs.rdev", 11)) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 236 | rdev = atoi(buf + 12); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 237 | } |
| 238 | memset(buf, 0, ATTR_MAX); |
| 239 | } |
| 240 | fclose(fp); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 241 | |
| 242 | update_map_file: |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 243 | fp = local_fopenat(map_dirfd, name, "w"); |
| 244 | close_preserve_errno(map_dirfd); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 245 | if (!fp) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 246 | return -1; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | if (credp->fc_uid != -1) { |
| 250 | uid = credp->fc_uid; |
| 251 | } |
| 252 | if (credp->fc_gid != -1) { |
| 253 | gid = credp->fc_gid; |
| 254 | } |
| 255 | if (credp->fc_mode != -1) { |
| 256 | mode = credp->fc_mode; |
| 257 | } |
| 258 | if (credp->fc_rdev != -1) { |
| 259 | rdev = credp->fc_rdev; |
| 260 | } |
| 261 | |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 262 | if (uid != -1) { |
| 263 | fprintf(fp, "virtfs.uid=%d\n", uid); |
| 264 | } |
| 265 | if (gid != -1) { |
| 266 | fprintf(fp, "virtfs.gid=%d\n", gid); |
| 267 | } |
| 268 | if (mode != -1) { |
| 269 | fprintf(fp, "virtfs.mode=%d\n", mode); |
| 270 | } |
| 271 | if (rdev != -1) { |
| 272 | fprintf(fp, "virtfs.rdev=%d\n", rdev); |
| 273 | } |
| 274 | fclose(fp); |
| 275 | |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode) |
| 280 | { |
| 281 | int fd, ret; |
| 282 | |
| 283 | /* FIXME: this should be handled with fchmodat(AT_SYMLINK_NOFOLLOW). |
| 284 | * Unfortunately, the linux kernel doesn't implement it yet. As an |
| 285 | * alternative, let's open the file and use fchmod() instead. This |
| 286 | * may fail depending on the permissions of the file, but it is the |
| 287 | * best we can do to avoid TOCTTOU. We first try to open read-only |
| 288 | * in case name points to a directory. If that fails, we try write-only |
| 289 | * in case name doesn't point to a directory. |
| 290 | */ |
| 291 | fd = openat_file(dirfd, name, O_RDONLY, 0); |
| 292 | if (fd == -1) { |
| 293 | /* In case the file is writable-only and isn't a directory. */ |
| 294 | if (errno == EACCES) { |
| 295 | fd = openat_file(dirfd, name, O_WRONLY, 0); |
| 296 | } |
| 297 | if (fd == -1 && errno == EISDIR) { |
| 298 | errno = EACCES; |
| 299 | } |
| 300 | } |
| 301 | if (fd == -1) { |
| 302 | return -1; |
| 303 | } |
| 304 | ret = fchmod(fd, mode); |
| 305 | close_preserve_errno(fd); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 306 | return ret; |
| 307 | } |
| 308 | |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 309 | static int local_set_xattrat(int dirfd, const char *path, FsCred *credp) |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 310 | { |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 311 | int err; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 312 | |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 313 | if (credp->fc_uid != -1) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 314 | uint32_t tmp_uid = cpu_to_le32(credp->fc_uid); |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 315 | err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.uid", &tmp_uid, |
| 316 | sizeof(uid_t), 0); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 317 | if (err) { |
| 318 | return err; |
| 319 | } |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 320 | } |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 321 | if (credp->fc_gid != -1) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 322 | uint32_t tmp_gid = cpu_to_le32(credp->fc_gid); |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 323 | err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.gid", &tmp_gid, |
| 324 | sizeof(gid_t), 0); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 325 | if (err) { |
| 326 | return err; |
| 327 | } |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 328 | } |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 329 | if (credp->fc_mode != -1) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 330 | uint32_t tmp_mode = cpu_to_le32(credp->fc_mode); |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 331 | err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.mode", &tmp_mode, |
| 332 | sizeof(mode_t), 0); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 333 | if (err) { |
| 334 | return err; |
| 335 | } |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 336 | } |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 337 | if (credp->fc_rdev != -1) { |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 338 | uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev); |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 339 | err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.rdev", &tmp_rdev, |
| 340 | sizeof(dev_t), 0); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 341 | if (err) { |
| 342 | return err; |
| 343 | } |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 344 | } |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 348 | static int local_set_cred_passthrough(FsContext *fs_ctx, int dirfd, |
| 349 | const char *name, FsCred *credp) |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 350 | { |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 351 | if (fchownat(dirfd, name, credp->fc_uid, credp->fc_gid, |
| 352 | AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH) < 0) { |
Aneesh Kumar K.V | 12848bf | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 353 | /* |
| 354 | * If we fail to change ownership and if we are |
| 355 | * using security model none. Ignore the error |
| 356 | */ |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 357 | if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) { |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 358 | return -1; |
Aneesh Kumar K.V | 12848bf | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 359 | } |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 360 | } |
M. Mohan Kumar | 2d40564 | 2012-01-19 12:21:12 +0530 | [diff] [blame] | 361 | |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 362 | return fchmodat_nofollow(dirfd, name, credp->fc_mode & 07777); |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 365 | static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path, |
| 366 | char *buf, size_t bufsz) |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 367 | { |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 368 | ssize_t tsize = -1; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 369 | |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 370 | if ((fs_ctx->export_flags & V9FS_SM_MAPPED) || |
| 371 | (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE)) { |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 372 | int fd; |
Greg Kurz | bec1e95 | 2017-02-26 23:43:40 +0100 | [diff] [blame] | 373 | |
| 374 | fd = local_open_nofollow(fs_ctx, fs_path->data, O_RDONLY, 0); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 375 | if (fd == -1) { |
| 376 | return -1; |
| 377 | } |
| 378 | do { |
| 379 | tsize = read(fd, (void *)buf, bufsz); |
| 380 | } while (tsize == -1 && errno == EINTR); |
Greg Kurz | bec1e95 | 2017-02-26 23:43:40 +0100 | [diff] [blame] | 381 | close_preserve_errno(fd); |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 382 | } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || |
| 383 | (fs_ctx->export_flags & V9FS_SM_NONE)) { |
Greg Kurz | bec1e95 | 2017-02-26 23:43:40 +0100 | [diff] [blame] | 384 | char *dirpath = g_path_get_dirname(fs_path->data); |
| 385 | char *name = g_path_get_basename(fs_path->data); |
| 386 | int dirfd; |
| 387 | |
| 388 | dirfd = local_opendir_nofollow(fs_ctx, dirpath); |
| 389 | if (dirfd == -1) { |
| 390 | goto out; |
| 391 | } |
| 392 | |
| 393 | tsize = readlinkat(dirfd, name, buf, bufsz); |
| 394 | close_preserve_errno(dirfd); |
| 395 | out: |
| 396 | g_free(name); |
| 397 | g_free(dirpath); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 398 | } |
| 399 | return tsize; |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 400 | } |
| 401 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 402 | static int local_close(FsContext *ctx, V9fsFidOpenState *fs) |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 403 | { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 404 | return close(fs->fd); |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 405 | } |
| 406 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 407 | static int local_closedir(FsContext *ctx, V9fsFidOpenState *fs) |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 408 | { |
Greg Kurz | f314ea4 | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 409 | return closedir(fs->dir.stream); |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 410 | } |
Anthony Liguori | 9f10751 | 2010-04-29 17:44:44 +0530 | [diff] [blame] | 411 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 412 | static int local_open(FsContext *ctx, V9fsPath *fs_path, |
| 413 | int flags, V9fsFidOpenState *fs) |
Anthony Liguori | a6568fe | 2010-04-29 17:44:55 +0530 | [diff] [blame] | 414 | { |
Greg Kurz | 21328e1 | 2017-02-26 23:41:55 +0100 | [diff] [blame] | 415 | int fd; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 416 | |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 417 | fd = local_open_nofollow(ctx, fs_path->data, flags, 0); |
Greg Kurz | 21328e1 | 2017-02-26 23:41:55 +0100 | [diff] [blame] | 418 | if (fd == -1) { |
| 419 | return -1; |
| 420 | } |
| 421 | fs->fd = fd; |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 422 | return fs->fd; |
Anthony Liguori | a6568fe | 2010-04-29 17:44:55 +0530 | [diff] [blame] | 423 | } |
| 424 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 425 | static int local_opendir(FsContext *ctx, |
| 426 | V9fsPath *fs_path, V9fsFidOpenState *fs) |
Anthony Liguori | a6568fe | 2010-04-29 17:44:55 +0530 | [diff] [blame] | 427 | { |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 428 | int dirfd; |
Greg Kurz | 21328e1 | 2017-02-26 23:41:55 +0100 | [diff] [blame] | 429 | DIR *stream; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 430 | |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 431 | dirfd = local_opendir_nofollow(ctx, fs_path->data); |
| 432 | if (dirfd == -1) { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 433 | return -1; |
| 434 | } |
Greg Kurz | 996a0d7 | 2017-02-26 23:42:18 +0100 | [diff] [blame] | 435 | |
| 436 | stream = fdopendir(dirfd); |
Greg Kurz | 21328e1 | 2017-02-26 23:41:55 +0100 | [diff] [blame] | 437 | if (!stream) { |
Greg Kurz | faab207 | 2017-03-06 17:34:01 +0100 | [diff] [blame^] | 438 | close(dirfd); |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 439 | return -1; |
| 440 | } |
Greg Kurz | 21328e1 | 2017-02-26 23:41:55 +0100 | [diff] [blame] | 441 | fs->dir.stream = stream; |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 442 | return 0; |
Anthony Liguori | a6568fe | 2010-04-29 17:44:55 +0530 | [diff] [blame] | 443 | } |
| 444 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 445 | static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 446 | { |
Greg Kurz | f314ea4 | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 447 | rewinddir(fs->dir.stream); |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 448 | } |
| 449 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 450 | static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs) |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 451 | { |
Greg Kurz | f314ea4 | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 452 | return telldir(fs->dir.stream); |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 453 | } |
| 454 | |
Greg Kurz | 635324e | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 455 | static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 456 | { |
Greg Kurz | 635324e | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 457 | struct dirent *entry; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 458 | |
| 459 | again: |
Greg Kurz | 635324e | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 460 | entry = readdir(fs->dir.stream); |
| 461 | if (!entry) { |
| 462 | return NULL; |
| 463 | } |
| 464 | |
Bastian Blank | 840a1bf | 2014-08-22 13:22:21 +0400 | [diff] [blame] | 465 | if (ctx->export_flags & V9FS_SM_MAPPED) { |
| 466 | entry->d_type = DT_UNKNOWN; |
| 467 | } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
Greg Kurz | 635324e | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 468 | if (!strcmp(entry->d_name, VIRTFS_META_DIR)) { |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 469 | /* skp the meta data directory */ |
| 470 | goto again; |
| 471 | } |
Bastian Blank | 840a1bf | 2014-08-22 13:22:21 +0400 | [diff] [blame] | 472 | entry->d_type = DT_UNKNOWN; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 473 | } |
Greg Kurz | 635324e | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 474 | |
| 475 | return entry; |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 476 | } |
| 477 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 478 | static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 479 | { |
Greg Kurz | f314ea4 | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 480 | seekdir(fs->dir.stream, off); |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 481 | } |
| 482 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 483 | static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs, |
| 484 | const struct iovec *iov, |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 485 | int iovcnt, off_t offset) |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 486 | { |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 487 | #ifdef CONFIG_PREADV |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 488 | return preadv(fs->fd, iov, iovcnt, offset); |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 489 | #else |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 490 | int err = lseek(fs->fd, offset, SEEK_SET); |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 491 | if (err == -1) { |
| 492 | return err; |
| 493 | } else { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 494 | return readv(fs->fd, iov, iovcnt); |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 495 | } |
| 496 | #endif |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 497 | } |
| 498 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 499 | static ssize_t local_pwritev(FsContext *ctx, V9fsFidOpenState *fs, |
| 500 | const struct iovec *iov, |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 501 | int iovcnt, off_t offset) |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 502 | { |
Greg Kurz | 6fe76ac | 2017-01-23 09:46:13 +0100 | [diff] [blame] | 503 | ssize_t ret; |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 504 | #ifdef CONFIG_PREADV |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 505 | ret = pwritev(fs->fd, iov, iovcnt, offset); |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 506 | #else |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 507 | int err = lseek(fs->fd, offset, SEEK_SET); |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 508 | if (err == -1) { |
| 509 | return err; |
| 510 | } else { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 511 | ret = writev(fs->fd, iov, iovcnt); |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 512 | } |
| 513 | #endif |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 514 | #ifdef CONFIG_SYNC_FILE_RANGE |
| 515 | if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) { |
| 516 | /* |
| 517 | * Initiate a writeback. This is not a data integrity sync. |
| 518 | * We want to ensure that we don't leave dirty pages in the cache |
| 519 | * after write when writeout=immediate is sepcified. |
| 520 | */ |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 521 | sync_file_range(fs->fd, offset, ret, |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 522 | SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE); |
| 523 | } |
| 524 | #endif |
| 525 | return ret; |
Anthony Liguori | 8449360 | 2010-04-29 17:44:58 +0530 | [diff] [blame] | 526 | } |
| 527 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 528 | static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 529 | { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 530 | char *dirpath = g_path_get_dirname(fs_path->data); |
| 531 | char *name = g_path_get_basename(fs_path->data); |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 532 | int ret = -1; |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 533 | int dirfd; |
| 534 | |
| 535 | dirfd = local_opendir_nofollow(fs_ctx, dirpath); |
| 536 | if (dirfd == -1) { |
| 537 | goto out; |
| 538 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 539 | |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 540 | if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 541 | ret = local_set_xattrat(dirfd, name, credp); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 542 | } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 543 | ret = local_set_mapped_file_attrat(dirfd, name, credp); |
| 544 | } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH || |
| 545 | fs_ctx->export_flags & V9FS_SM_NONE) { |
| 546 | ret = fchmodat_nofollow(dirfd, name, credp->fc_mode); |
Venkateswararao Jujjuri (JV) | e95ead3 | 2010-06-14 13:34:42 -0700 | [diff] [blame] | 547 | } |
Greg Kurz | e3187a4 | 2017-02-26 23:44:28 +0100 | [diff] [blame] | 548 | close_preserve_errno(dirfd); |
| 549 | |
| 550 | out: |
| 551 | g_free(dirpath); |
| 552 | g_free(name); |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 553 | return ret; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 554 | } |
| 555 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 556 | static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, |
| 557 | const char *name, FsCred *credp) |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 558 | { |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 559 | int err = -1; |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 560 | int dirfd; |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 561 | |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 562 | dirfd = local_opendir_nofollow(fs_ctx, dir_path->data); |
| 563 | if (dirfd == -1) { |
| 564 | return -1; |
| 565 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 566 | |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 567 | if (fs_ctx->export_flags & V9FS_SM_MAPPED || |
| 568 | fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
| 569 | err = mknodat(dirfd, name, SM_LOCAL_MODE_BITS | S_IFREG, 0); |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 570 | if (err == -1) { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 571 | goto out; |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 572 | } |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 573 | |
| 574 | if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
| 575 | err = local_set_xattrat(dirfd, name, credp); |
| 576 | } else { |
| 577 | err = local_set_mapped_file_attrat(dirfd, name, credp); |
| 578 | } |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 579 | if (err == -1) { |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 580 | goto err_end; |
| 581 | } |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 582 | } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH || |
| 583 | fs_ctx->export_flags & V9FS_SM_NONE) { |
| 584 | err = mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 585 | if (err == -1) { |
| 586 | goto out; |
| 587 | } |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 588 | err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 589 | if (err == -1) { |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 590 | goto err_end; |
| 591 | } |
| 592 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 593 | goto out; |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 594 | |
| 595 | err_end: |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 596 | unlinkat_preserve_errno(dirfd, name, 0); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 597 | out: |
Greg Kurz | d815e72 | 2017-02-26 23:44:54 +0100 | [diff] [blame] | 598 | close_preserve_errno(dirfd); |
Venkateswararao Jujjuri (JV) | 1c29331 | 2010-06-14 13:34:48 -0700 | [diff] [blame] | 599 | return err; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 600 | } |
| 601 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 602 | static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path, |
| 603 | const char *name, FsCred *credp) |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 604 | { |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 605 | int err = -1; |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 606 | int dirfd; |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 607 | |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 608 | dirfd = local_opendir_nofollow(fs_ctx, dir_path->data); |
| 609 | if (dirfd == -1) { |
| 610 | return -1; |
| 611 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 612 | |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 613 | if (fs_ctx->export_flags & V9FS_SM_MAPPED || |
| 614 | fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
| 615 | err = mkdirat(dirfd, name, SM_LOCAL_DIR_MODE_BITS); |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 616 | if (err == -1) { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 617 | goto out; |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 618 | } |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 619 | credp->fc_mode = credp->fc_mode | S_IFDIR; |
| 620 | |
| 621 | if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
| 622 | err = local_set_xattrat(dirfd, name, credp); |
| 623 | } else { |
| 624 | err = local_set_mapped_file_attrat(dirfd, name, credp); |
| 625 | } |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 626 | if (err == -1) { |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 627 | goto err_end; |
| 628 | } |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 629 | } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH || |
| 630 | fs_ctx->export_flags & V9FS_SM_NONE) { |
| 631 | err = mkdirat(dirfd, name, credp->fc_mode); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 632 | if (err == -1) { |
| 633 | goto out; |
| 634 | } |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 635 | err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 636 | if (err == -1) { |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 637 | goto err_end; |
| 638 | } |
| 639 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 640 | goto out; |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 641 | |
| 642 | err_end: |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 643 | unlinkat_preserve_errno(dirfd, name, AT_REMOVEDIR); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 644 | out: |
Greg Kurz | 3f3a169 | 2017-02-26 23:45:02 +0100 | [diff] [blame] | 645 | close_preserve_errno(dirfd); |
Venkateswararao Jujjuri (JV) | 00ec5c3 | 2010-06-14 13:34:46 -0700 | [diff] [blame] | 646 | return err; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 647 | } |
| 648 | |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 649 | static int local_fstat(FsContext *fs_ctx, int fid_type, |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 650 | V9fsFidOpenState *fs, struct stat *stbuf) |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 651 | { |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 652 | int err, fd; |
| 653 | |
| 654 | if (fid_type == P9_FID_DIR) { |
Greg Kurz | f314ea4 | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 655 | fd = dirfd(fs->dir.stream); |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 656 | } else { |
| 657 | fd = fs->fd; |
| 658 | } |
| 659 | |
| 660 | err = fstat(fd, stbuf); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 661 | if (err) { |
| 662 | return err; |
| 663 | } |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 664 | if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 665 | /* Actual credentials are part of extended attrs */ |
| 666 | uid_t tmp_uid; |
| 667 | gid_t tmp_gid; |
| 668 | mode_t tmp_mode; |
| 669 | dev_t tmp_dev; |
| 670 | |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 671 | if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) { |
| 672 | stbuf->st_uid = le32_to_cpu(tmp_uid); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 673 | } |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 674 | if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) { |
| 675 | stbuf->st_gid = le32_to_cpu(tmp_gid); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 676 | } |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 677 | if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) { |
| 678 | stbuf->st_mode = le32_to_cpu(tmp_mode); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 679 | } |
Aneesh Kumar K.V | f8ad4a8 | 2014-08-03 17:02:55 +0530 | [diff] [blame] | 680 | if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) { |
| 681 | stbuf->st_rdev = le64_to_cpu(tmp_dev); |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 682 | } |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 683 | } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
| 684 | errno = EOPNOTSUPP; |
| 685 | return -1; |
Venkateswararao Jujjuri (JV) | 1237ad7 | 2010-06-14 13:34:44 -0700 | [diff] [blame] | 686 | } |
| 687 | return err; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 688 | } |
| 689 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 690 | static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 691 | int flags, FsCred *credp, V9fsFidOpenState *fs) |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 692 | { |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 693 | int fd = -1; |
| 694 | int err = -1; |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 695 | int dirfd; |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 696 | |
Aneesh Kumar K.V | 0ceb092 | 2013-05-20 19:43:15 +0530 | [diff] [blame] | 697 | /* |
| 698 | * Mark all the open to not follow symlinks |
| 699 | */ |
| 700 | flags |= O_NOFOLLOW; |
| 701 | |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 702 | dirfd = local_opendir_nofollow(fs_ctx, dir_path->data); |
| 703 | if (dirfd == -1) { |
| 704 | return -1; |
| 705 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 706 | |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 707 | /* Determine the security model */ |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 708 | if (fs_ctx->export_flags & V9FS_SM_MAPPED || |
| 709 | fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
| 710 | fd = openat_file(dirfd, name, flags, SM_LOCAL_MODE_BITS); |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 711 | if (fd == -1) { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 712 | goto out; |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 713 | } |
| 714 | credp->fc_mode = credp->fc_mode|S_IFREG; |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 715 | if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
| 716 | /* Set cleint credentials in xattr */ |
| 717 | err = local_set_xattrat(dirfd, name, credp); |
| 718 | } else { |
| 719 | err = local_set_mapped_file_attrat(dirfd, name, credp); |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 720 | } |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 721 | if (err == -1) { |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 722 | goto err_end; |
| 723 | } |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 724 | } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || |
| 725 | (fs_ctx->export_flags & V9FS_SM_NONE)) { |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 726 | fd = openat_file(dirfd, name, flags, credp->fc_mode); |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 727 | if (fd == -1) { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 728 | goto out; |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 729 | } |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 730 | err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp); |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 731 | if (err == -1) { |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 732 | goto err_end; |
| 733 | } |
| 734 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 735 | err = fd; |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 736 | fs->fd = fd; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 737 | goto out; |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 738 | |
| 739 | err_end: |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 740 | unlinkat_preserve_errno(dirfd, name, |
| 741 | flags & O_DIRECTORY ? AT_REMOVEDIR : 0); |
| 742 | close_preserve_errno(fd); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 743 | out: |
Greg Kurz | a565fea | 2017-02-26 23:45:09 +0100 | [diff] [blame] | 744 | close_preserve_errno(dirfd); |
Venkateswararao Jujjuri (JV) | 4750a96 | 2010-06-14 13:34:45 -0700 | [diff] [blame] | 745 | return err; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 746 | } |
| 747 | |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 748 | |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 749 | static int local_symlink(FsContext *fs_ctx, const char *oldpath, |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 750 | V9fsPath *dir_path, const char *name, FsCred *credp) |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 751 | { |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 752 | int err = -1; |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 753 | int dirfd; |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 754 | |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 755 | dirfd = local_opendir_nofollow(fs_ctx, dir_path->data); |
| 756 | if (dirfd == -1) { |
| 757 | return -1; |
| 758 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 759 | |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 760 | /* Determine the security model */ |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 761 | if (fs_ctx->export_flags & V9FS_SM_MAPPED || |
| 762 | fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 763 | int fd; |
| 764 | ssize_t oldpath_size, write_size; |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 765 | |
| 766 | fd = openat_file(dirfd, name, O_CREAT | O_EXCL | O_RDWR, |
| 767 | SM_LOCAL_MODE_BITS); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 768 | if (fd == -1) { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 769 | goto out; |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 770 | } |
| 771 | /* Write the oldpath (target) to the file. */ |
Harsh Prateek Bora | f35bde2 | 2011-02-02 10:20:33 +0530 | [diff] [blame] | 772 | oldpath_size = strlen(oldpath); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 773 | do { |
| 774 | write_size = write(fd, (void *)oldpath, oldpath_size); |
| 775 | } while (write_size == -1 && errno == EINTR); |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 776 | close_preserve_errno(fd); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 777 | |
| 778 | if (write_size != oldpath_size) { |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 779 | goto err_end; |
| 780 | } |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 781 | /* Set cleint credentials in symlink's xattr */ |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 782 | credp->fc_mode = credp->fc_mode | S_IFLNK; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 783 | |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 784 | if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
| 785 | err = local_set_xattrat(dirfd, name, credp); |
| 786 | } else { |
| 787 | err = local_set_mapped_file_attrat(dirfd, name, credp); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 788 | } |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 789 | if (err == -1) { |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 790 | goto err_end; |
| 791 | } |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 792 | } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH || |
| 793 | fs_ctx->export_flags & V9FS_SM_NONE) { |
| 794 | err = symlinkat(oldpath, dirfd, name); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 795 | if (err) { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 796 | goto out; |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 797 | } |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 798 | err = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid, |
| 799 | AT_SYMLINK_NOFOLLOW); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 800 | if (err == -1) { |
Aneesh Kumar K.V | 12848bf | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 801 | /* |
| 802 | * If we fail to change ownership and if we are |
| 803 | * using security model none. Ignore the error |
| 804 | */ |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 805 | if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) { |
Aneesh Kumar K.V | 12848bf | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 806 | goto err_end; |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 807 | } else { |
Aneesh Kumar K.V | 12848bf | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 808 | err = 0; |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 809 | } |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 810 | } |
| 811 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 812 | goto out; |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 813 | |
| 814 | err_end: |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 815 | unlinkat_preserve_errno(dirfd, name, 0); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 816 | out: |
Greg Kurz | 3877161 | 2017-02-26 23:44:46 +0100 | [diff] [blame] | 817 | close_preserve_errno(dirfd); |
Venkateswararao Jujjuri (JV) | 879c281 | 2010-06-14 13:34:47 -0700 | [diff] [blame] | 818 | return err; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 819 | } |
| 820 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 821 | static int local_link(FsContext *ctx, V9fsPath *oldpath, |
| 822 | V9fsPath *dirpath, const char *name) |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 823 | { |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 824 | char *odirpath = g_path_get_dirname(oldpath->data); |
| 825 | char *oname = g_path_get_basename(oldpath->data); |
| 826 | int ret = -1; |
| 827 | int odirfd, ndirfd; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 828 | |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 829 | odirfd = local_opendir_nofollow(ctx, odirpath); |
| 830 | if (odirfd == -1) { |
Greg Kurz | 6dd4b1f | 2017-02-26 23:44:11 +0100 | [diff] [blame] | 831 | goto out; |
| 832 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 833 | |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 834 | ndirfd = local_opendir_nofollow(ctx, dirpath->data); |
| 835 | if (ndirfd == -1) { |
| 836 | close_preserve_errno(odirfd); |
| 837 | goto out; |
| 838 | } |
| 839 | |
| 840 | ret = linkat(odirfd, oname, ndirfd, name, 0); |
| 841 | if (ret < 0) { |
| 842 | goto out_close; |
| 843 | } |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 844 | |
| 845 | /* now link the virtfs_metadata files */ |
Greg Kurz | 6dd4b1f | 2017-02-26 23:44:11 +0100 | [diff] [blame] | 846 | if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 847 | int omap_dirfd, nmap_dirfd; |
Greg Kurz | 6dd4b1f | 2017-02-26 23:44:11 +0100 | [diff] [blame] | 848 | |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 849 | ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700); |
| 850 | if (ret < 0 && errno != EEXIST) { |
| 851 | goto err_undo_link; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 852 | } |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 853 | |
| 854 | omap_dirfd = openat_dir(odirfd, VIRTFS_META_DIR); |
| 855 | if (omap_dirfd == -1) { |
| 856 | goto err; |
| 857 | } |
| 858 | |
| 859 | nmap_dirfd = openat_dir(ndirfd, VIRTFS_META_DIR); |
| 860 | if (nmap_dirfd == -1) { |
| 861 | close_preserve_errno(omap_dirfd); |
| 862 | goto err; |
| 863 | } |
| 864 | |
| 865 | ret = linkat(omap_dirfd, oname, nmap_dirfd, name, 0); |
| 866 | close_preserve_errno(nmap_dirfd); |
| 867 | close_preserve_errno(omap_dirfd); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 868 | if (ret < 0 && errno != ENOENT) { |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 869 | goto err_undo_link; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 870 | } |
Greg Kurz | 6dd4b1f | 2017-02-26 23:44:11 +0100 | [diff] [blame] | 871 | |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 872 | ret = 0; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 873 | } |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 874 | goto out_close; |
| 875 | |
| 876 | err: |
| 877 | ret = -1; |
| 878 | err_undo_link: |
| 879 | unlinkat_preserve_errno(ndirfd, name, 0); |
| 880 | out_close: |
| 881 | close_preserve_errno(ndirfd); |
| 882 | close_preserve_errno(odirfd); |
Greg Kurz | 6dd4b1f | 2017-02-26 23:44:11 +0100 | [diff] [blame] | 883 | out: |
Greg Kurz | ad0b46e | 2017-02-26 23:44:20 +0100 | [diff] [blame] | 884 | g_free(oname); |
| 885 | g_free(odirpath); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 886 | return ret; |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 887 | } |
| 888 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 889 | static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size) |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 890 | { |
Greg Kurz | ac125d9 | 2017-02-26 23:43:32 +0100 | [diff] [blame] | 891 | int fd, ret; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 892 | |
Greg Kurz | ac125d9 | 2017-02-26 23:43:32 +0100 | [diff] [blame] | 893 | fd = local_open_nofollow(ctx, fs_path->data, O_WRONLY, 0); |
| 894 | if (fd == -1) { |
| 895 | return -1; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 896 | } |
Greg Kurz | ac125d9 | 2017-02-26 23:43:32 +0100 | [diff] [blame] | 897 | ret = ftruncate(fd, size); |
| 898 | close_preserve_errno(fd); |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 899 | return ret; |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 900 | } |
| 901 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 902 | static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 903 | { |
Greg Kurz | d369f20 | 2017-02-26 23:44:37 +0100 | [diff] [blame] | 904 | char *dirpath = g_path_get_dirname(fs_path->data); |
| 905 | char *name = g_path_get_basename(fs_path->data); |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 906 | int ret = -1; |
Greg Kurz | d369f20 | 2017-02-26 23:44:37 +0100 | [diff] [blame] | 907 | int dirfd; |
| 908 | |
| 909 | dirfd = local_opendir_nofollow(fs_ctx, dirpath); |
| 910 | if (dirfd == -1) { |
| 911 | goto out; |
| 912 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 913 | |
Sripathi Kodi | c79ce73 | 2010-06-17 18:18:47 +0530 | [diff] [blame] | 914 | if ((credp->fc_uid == -1 && credp->fc_gid == -1) || |
Aneesh Kumar K.V | 17b1971 | 2011-10-25 12:10:39 +0530 | [diff] [blame] | 915 | (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || |
| 916 | (fs_ctx->export_flags & V9FS_SM_NONE)) { |
Greg Kurz | d369f20 | 2017-02-26 23:44:37 +0100 | [diff] [blame] | 917 | ret = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid, |
| 918 | AT_SYMLINK_NOFOLLOW); |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 919 | } else if (fs_ctx->export_flags & V9FS_SM_MAPPED) { |
Greg Kurz | d369f20 | 2017-02-26 23:44:37 +0100 | [diff] [blame] | 920 | ret = local_set_xattrat(dirfd, name, credp); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 921 | } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
Greg Kurz | d369f20 | 2017-02-26 23:44:37 +0100 | [diff] [blame] | 922 | ret = local_set_mapped_file_attrat(dirfd, name, credp); |
Venkateswararao Jujjuri (JV) | f7613be | 2010-06-14 13:34:43 -0700 | [diff] [blame] | 923 | } |
Greg Kurz | d369f20 | 2017-02-26 23:44:37 +0100 | [diff] [blame] | 924 | |
| 925 | close_preserve_errno(dirfd); |
| 926 | out: |
| 927 | g_free(name); |
| 928 | g_free(dirpath); |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 929 | return ret; |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 930 | } |
| 931 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 932 | static int local_utimensat(FsContext *s, V9fsPath *fs_path, |
Hidetoshi Seto | 3867142 | 2010-11-24 11:38:10 +0900 | [diff] [blame] | 933 | const struct timespec *buf) |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 934 | { |
Greg Kurz | a33eda0 | 2017-02-26 23:43:17 +0100 | [diff] [blame] | 935 | char *dirpath = g_path_get_dirname(fs_path->data); |
| 936 | char *name = g_path_get_basename(fs_path->data); |
| 937 | int dirfd, ret = -1; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 938 | |
Greg Kurz | a33eda0 | 2017-02-26 23:43:17 +0100 | [diff] [blame] | 939 | dirfd = local_opendir_nofollow(s, dirpath); |
| 940 | if (dirfd == -1) { |
| 941 | goto out; |
| 942 | } |
| 943 | |
| 944 | ret = utimensat(dirfd, name, buf, AT_SYMLINK_NOFOLLOW); |
| 945 | close_preserve_errno(dirfd); |
| 946 | out: |
| 947 | g_free(dirpath); |
| 948 | g_free(name); |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 949 | return ret; |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 950 | } |
| 951 | |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 952 | static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name, |
| 953 | int flags) |
Anthony Liguori | 5bae190 | 2010-04-29 17:45:01 +0530 | [diff] [blame] | 954 | { |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 955 | int ret = -1; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 956 | |
| 957 | if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 958 | int map_dirfd; |
| 959 | |
| 960 | if (flags == AT_REMOVEDIR) { |
| 961 | int fd; |
| 962 | |
| 963 | fd = openat(dirfd, name, O_RDONLY | O_DIRECTORY | O_PATH); |
| 964 | if (fd == -1) { |
| 965 | goto err_out; |
| 966 | } |
| 967 | /* |
| 968 | * If directory remove .virtfs_metadata contained in the |
| 969 | * directory |
| 970 | */ |
| 971 | ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR); |
| 972 | close_preserve_errno(fd); |
| 973 | if (ret < 0 && errno != ENOENT) { |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 974 | /* |
| 975 | * We didn't had the .virtfs_metadata file. May be file created |
| 976 | * in non-mapped mode ?. Ignore ENOENT. |
| 977 | */ |
| 978 | goto err_out; |
| 979 | } |
| 980 | } |
| 981 | /* |
| 982 | * Now remove the name from parent directory |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 983 | * .virtfs_metadata directory. |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 984 | */ |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 985 | map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR); |
| 986 | ret = unlinkat(map_dirfd, name, 0); |
| 987 | close_preserve_errno(map_dirfd); |
| 988 | if (ret < 0 && errno != ENOENT) { |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 989 | /* |
| 990 | * We didn't had the .virtfs_metadata file. May be file created |
| 991 | * in non-mapped mode ?. Ignore ENOENT. |
| 992 | */ |
| 993 | goto err_out; |
| 994 | } |
| 995 | } |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 996 | |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 997 | ret = unlinkat(dirfd, name, flags); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 998 | err_out: |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 999 | return ret; |
| 1000 | } |
| 1001 | |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1002 | static int local_remove(FsContext *ctx, const char *path) |
| 1003 | { |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1004 | struct stat stbuf; |
Greg Kurz | a0e640a | 2017-02-26 23:43:08 +0100 | [diff] [blame] | 1005 | char *dirpath = g_path_get_dirname(path); |
| 1006 | char *name = g_path_get_basename(path); |
| 1007 | int flags = 0; |
| 1008 | int dirfd; |
| 1009 | int err = -1; |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1010 | |
Greg Kurz | a0e640a | 2017-02-26 23:43:08 +0100 | [diff] [blame] | 1011 | dirfd = local_opendir_nofollow(ctx, dirpath); |
Greg Kurz | b7361d4 | 2017-03-06 17:34:01 +0100 | [diff] [blame] | 1012 | if (dirfd == -1) { |
Greg Kurz | a0e640a | 2017-02-26 23:43:08 +0100 | [diff] [blame] | 1013 | goto out; |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1014 | } |
Anthony Liguori | 5bae190 | 2010-04-29 17:45:01 +0530 | [diff] [blame] | 1015 | |
Greg Kurz | a0e640a | 2017-02-26 23:43:08 +0100 | [diff] [blame] | 1016 | if (fstatat(dirfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0) { |
| 1017 | goto err_out; |
| 1018 | } |
| 1019 | |
| 1020 | if (S_ISDIR(stbuf.st_mode)) { |
| 1021 | flags |= AT_REMOVEDIR; |
| 1022 | } |
| 1023 | |
| 1024 | err = local_unlinkat_common(ctx, dirfd, name, flags); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 1025 | err_out: |
Greg Kurz | a0e640a | 2017-02-26 23:43:08 +0100 | [diff] [blame] | 1026 | close_preserve_errno(dirfd); |
| 1027 | out: |
| 1028 | g_free(name); |
| 1029 | g_free(dirpath); |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 1030 | return err; |
Anthony Liguori | 5bae190 | 2010-04-29 17:45:01 +0530 | [diff] [blame] | 1031 | } |
| 1032 | |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 1033 | static int local_fsync(FsContext *ctx, int fid_type, |
| 1034 | V9fsFidOpenState *fs, int datasync) |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1035 | { |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 1036 | int fd; |
| 1037 | |
| 1038 | if (fid_type == P9_FID_DIR) { |
Greg Kurz | f314ea4 | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 1039 | fd = dirfd(fs->dir.stream); |
Venkateswararao Jujjuri (JV) | 4959497 | 2010-10-22 10:08:45 -0700 | [diff] [blame] | 1040 | } else { |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 1041 | fd = fs->fd; |
| 1042 | } |
| 1043 | |
| 1044 | if (datasync) { |
| 1045 | return qemu_fdatasync(fd); |
| 1046 | } else { |
| 1047 | return fsync(fd); |
Venkateswararao Jujjuri (JV) | 4959497 | 2010-10-22 10:08:45 -0700 | [diff] [blame] | 1048 | } |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1049 | } |
| 1050 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1051 | static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf) |
M. Mohan Kumar | be940c8 | 2010-05-10 12:11:03 +0530 | [diff] [blame] | 1052 | { |
Greg Kurz | 31e51d1 | 2017-02-26 23:43:25 +0100 | [diff] [blame] | 1053 | int fd, ret; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1054 | |
Greg Kurz | 31e51d1 | 2017-02-26 23:43:25 +0100 | [diff] [blame] | 1055 | fd = local_open_nofollow(s, fs_path->data, O_RDONLY, 0); |
| 1056 | ret = fstatfs(fd, stbuf); |
| 1057 | close_preserve_errno(fd); |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 1058 | return ret; |
M. Mohan Kumar | be940c8 | 2010-05-10 12:11:03 +0530 | [diff] [blame] | 1059 | } |
| 1060 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1061 | static ssize_t local_lgetxattr(FsContext *ctx, V9fsPath *fs_path, |
Aneesh Kumar K.V | fa32ef8 | 2010-09-02 11:09:06 +0530 | [diff] [blame] | 1062 | const char *name, void *value, size_t size) |
| 1063 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1064 | char *path = fs_path->data; |
| 1065 | |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 1066 | return v9fs_get_xattr(ctx, path, name, value, size); |
Aneesh Kumar K.V | fa32ef8 | 2010-09-02 11:09:06 +0530 | [diff] [blame] | 1067 | } |
| 1068 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1069 | static ssize_t local_llistxattr(FsContext *ctx, V9fsPath *fs_path, |
Aneesh Kumar K.V | fa32ef8 | 2010-09-02 11:09:06 +0530 | [diff] [blame] | 1070 | void *value, size_t size) |
| 1071 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1072 | char *path = fs_path->data; |
| 1073 | |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 1074 | return v9fs_list_xattr(ctx, path, value, size); |
Aneesh Kumar K.V | fa32ef8 | 2010-09-02 11:09:06 +0530 | [diff] [blame] | 1075 | } |
| 1076 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1077 | static int local_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name, |
Aneesh Kumar K.V | 10b468b | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 1078 | void *value, size_t size, int flags) |
| 1079 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1080 | char *path = fs_path->data; |
| 1081 | |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 1082 | return v9fs_set_xattr(ctx, path, name, value, size, flags); |
Aneesh Kumar K.V | 10b468b | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 1083 | } |
| 1084 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1085 | static int local_lremovexattr(FsContext *ctx, V9fsPath *fs_path, |
| 1086 | const char *name) |
Aneesh Kumar K.V | 9ed3ef2 | 2010-08-26 11:15:23 +0530 | [diff] [blame] | 1087 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1088 | char *path = fs_path->data; |
| 1089 | |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 1090 | return v9fs_remove_xattr(ctx, path, name); |
Aneesh Kumar K.V | 9ed3ef2 | 2010-08-26 11:15:23 +0530 | [diff] [blame] | 1091 | } |
| 1092 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1093 | static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path, |
| 1094 | const char *name, V9fsPath *target) |
| 1095 | { |
| 1096 | if (dir_path) { |
Greg Kurz | e3e83f2 | 2016-09-16 08:56:15 +0200 | [diff] [blame] | 1097 | v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1098 | } else { |
Greg Kurz | e3e83f2 | 2016-09-16 08:56:15 +0200 | [diff] [blame] | 1099 | v9fs_path_sprintf(target, "%s", name); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1100 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | static int local_renameat(FsContext *ctx, V9fsPath *olddir, |
| 1105 | const char *old_name, V9fsPath *newdir, |
| 1106 | const char *new_name) |
| 1107 | { |
| 1108 | int ret; |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 1109 | int odirfd, ndirfd; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1110 | |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 1111 | odirfd = local_opendir_nofollow(ctx, olddir->data); |
| 1112 | if (odirfd == -1) { |
| 1113 | return -1; |
| 1114 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1115 | |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 1116 | ndirfd = local_opendir_nofollow(ctx, newdir->data); |
| 1117 | if (ndirfd == -1) { |
| 1118 | close_preserve_errno(odirfd); |
| 1119 | return -1; |
| 1120 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1121 | |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 1122 | ret = renameat(odirfd, old_name, ndirfd, new_name); |
| 1123 | if (ret < 0) { |
| 1124 | goto out; |
| 1125 | } |
| 1126 | |
| 1127 | if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
| 1128 | int omap_dirfd, nmap_dirfd; |
| 1129 | |
| 1130 | ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700); |
| 1131 | if (ret < 0 && errno != EEXIST) { |
| 1132 | goto err_undo_rename; |
| 1133 | } |
| 1134 | |
Greg Kurz | 6dd4b1f | 2017-02-26 23:44:11 +0100 | [diff] [blame] | 1135 | omap_dirfd = openat_dir(odirfd, VIRTFS_META_DIR); |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 1136 | if (omap_dirfd == -1) { |
| 1137 | goto err; |
| 1138 | } |
| 1139 | |
Greg Kurz | 6dd4b1f | 2017-02-26 23:44:11 +0100 | [diff] [blame] | 1140 | nmap_dirfd = openat_dir(ndirfd, VIRTFS_META_DIR); |
Greg Kurz | 99f2cf4 | 2017-02-26 23:43:55 +0100 | [diff] [blame] | 1141 | if (nmap_dirfd == -1) { |
| 1142 | close_preserve_errno(omap_dirfd); |
| 1143 | goto err; |
| 1144 | } |
| 1145 | |
| 1146 | /* rename the .virtfs_metadata files */ |
| 1147 | ret = renameat(omap_dirfd, old_name, nmap_dirfd, new_name); |
| 1148 | close_preserve_errno(nmap_dirfd); |
| 1149 | close_preserve_errno(omap_dirfd); |
| 1150 | if (ret < 0 && errno != ENOENT) { |
| 1151 | goto err_undo_rename; |
| 1152 | } |
| 1153 | |
| 1154 | ret = 0; |
| 1155 | } |
| 1156 | goto out; |
| 1157 | |
| 1158 | err: |
| 1159 | ret = -1; |
| 1160 | err_undo_rename: |
| 1161 | renameat_preserve_errno(ndirfd, new_name, odirfd, old_name); |
| 1162 | out: |
| 1163 | close_preserve_errno(ndirfd); |
| 1164 | close_preserve_errno(odirfd); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1165 | return ret; |
| 1166 | } |
| 1167 | |
Greg Kurz | d2767ed | 2017-02-26 23:44:03 +0100 | [diff] [blame] | 1168 | static void v9fs_path_init_dirname(V9fsPath *path, const char *str) |
| 1169 | { |
| 1170 | path->data = g_path_get_dirname(str); |
| 1171 | path->size = strlen(path->data) + 1; |
| 1172 | } |
| 1173 | |
| 1174 | static int local_rename(FsContext *ctx, const char *oldpath, |
| 1175 | const char *newpath) |
| 1176 | { |
| 1177 | int err; |
| 1178 | char *oname = g_path_get_basename(oldpath); |
| 1179 | char *nname = g_path_get_basename(newpath); |
| 1180 | V9fsPath olddir, newdir; |
| 1181 | |
| 1182 | v9fs_path_init_dirname(&olddir, oldpath); |
| 1183 | v9fs_path_init_dirname(&newdir, newpath); |
| 1184 | |
| 1185 | err = local_renameat(ctx, &olddir, oname, &newdir, nname); |
| 1186 | |
| 1187 | v9fs_path_free(&newdir); |
| 1188 | v9fs_path_free(&olddir); |
| 1189 | g_free(nname); |
| 1190 | g_free(oname); |
| 1191 | |
| 1192 | return err; |
| 1193 | } |
| 1194 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1195 | static int local_unlinkat(FsContext *ctx, V9fsPath *dir, |
| 1196 | const char *name, int flags) |
| 1197 | { |
| 1198 | int ret; |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 1199 | int dirfd; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 1200 | |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 1201 | dirfd = local_opendir_nofollow(ctx, dir->data); |
| 1202 | if (dirfd == -1) { |
| 1203 | return -1; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 1204 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1205 | |
Greg Kurz | df4938a | 2017-02-26 23:43:00 +0100 | [diff] [blame] | 1206 | ret = local_unlinkat_common(ctx, dirfd, name, flags); |
| 1207 | close_preserve_errno(dirfd); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1208 | return ret; |
| 1209 | } |
Aneesh Kumar K.V | 9ed3ef2 | 2010-08-26 11:15:23 +0530 | [diff] [blame] | 1210 | |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1211 | static int local_ioc_getversion(FsContext *ctx, V9fsPath *path, |
| 1212 | mode_t st_mode, uint64_t *st_gen) |
| 1213 | { |
Paolo Bonzini | ae0f940 | 2011-11-21 09:29:11 +0100 | [diff] [blame] | 1214 | #ifdef FS_IOC_GETVERSION |
Kirill A. Shutemov | 0e5fc99 | 2014-01-28 17:08:24 +0200 | [diff] [blame] | 1215 | int err; |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 1216 | V9fsFidOpenState fid_open; |
| 1217 | |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1218 | /* |
| 1219 | * Do not try to open special files like device nodes, fifos etc |
| 1220 | * We can get fd for regular files and directories only |
| 1221 | */ |
| 1222 | if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) { |
Kirill A. Shutemov | 1a9978a | 2014-01-28 17:08:26 +0200 | [diff] [blame] | 1223 | errno = ENOTTY; |
| 1224 | return -1; |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1225 | } |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 1226 | err = local_open(ctx, path, O_RDONLY, &fid_open); |
| 1227 | if (err < 0) { |
| 1228 | return err; |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1229 | } |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 1230 | err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen); |
| 1231 | local_close(ctx, &fid_open); |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1232 | return err; |
Kirill A. Shutemov | 0e5fc99 | 2014-01-28 17:08:24 +0200 | [diff] [blame] | 1233 | #else |
| 1234 | errno = ENOTTY; |
| 1235 | return -1; |
| 1236 | #endif |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1237 | } |
| 1238 | |
Aneesh Kumar K.V | 0174fe7 | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 1239 | static int local_init(FsContext *ctx) |
| 1240 | { |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1241 | struct statfs stbuf; |
Greg Kurz | 0e35a37 | 2017-02-26 23:42:10 +0100 | [diff] [blame] | 1242 | LocalData *data = g_malloc(sizeof(*data)); |
| 1243 | |
| 1244 | data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY); |
| 1245 | if (data->mountfd == -1) { |
| 1246 | goto err; |
| 1247 | } |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 1248 | |
Greg Kurz | 00c90bd | 2017-02-26 23:41:48 +0100 | [diff] [blame] | 1249 | #ifdef FS_IOC_GETVERSION |
| 1250 | /* |
| 1251 | * use ioc_getversion only if the ioctl is definied |
| 1252 | */ |
Greg Kurz | 0e35a37 | 2017-02-26 23:42:10 +0100 | [diff] [blame] | 1253 | if (fstatfs(data->mountfd, &stbuf) < 0) { |
| 1254 | close_preserve_errno(data->mountfd); |
| 1255 | goto err; |
Greg Kurz | 00c90bd | 2017-02-26 23:41:48 +0100 | [diff] [blame] | 1256 | } |
| 1257 | switch (stbuf.f_type) { |
| 1258 | case EXT2_SUPER_MAGIC: |
| 1259 | case BTRFS_SUPER_MAGIC: |
| 1260 | case REISERFS_SUPER_MAGIC: |
| 1261 | case XFS_SUPER_MAGIC: |
| 1262 | ctx->exops.get_st_gen = local_ioc_getversion; |
| 1263 | break; |
| 1264 | } |
| 1265 | #endif |
Aneesh Kumar K.V | 0174fe7 | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 1266 | |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 1267 | if (ctx->export_flags & V9FS_SM_PASSTHROUGH) { |
| 1268 | ctx->xops = passthrough_xattr_ops; |
| 1269 | } else if (ctx->export_flags & V9FS_SM_MAPPED) { |
| 1270 | ctx->xops = mapped_xattr_ops; |
| 1271 | } else if (ctx->export_flags & V9FS_SM_NONE) { |
| 1272 | ctx->xops = none_xattr_ops; |
| 1273 | } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { |
| 1274 | /* |
| 1275 | * xattr operation for mapped-file and passthrough |
| 1276 | * remain same. |
| 1277 | */ |
| 1278 | ctx->xops = passthrough_xattr_ops; |
| 1279 | } |
Aneesh Kumar K.V | c98f1d4 | 2011-10-12 20:59:18 +0530 | [diff] [blame] | 1280 | ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT; |
Greg Kurz | 00c90bd | 2017-02-26 23:41:48 +0100 | [diff] [blame] | 1281 | |
Greg Kurz | 0e35a37 | 2017-02-26 23:42:10 +0100 | [diff] [blame] | 1282 | ctx->private = data; |
Greg Kurz | 00c90bd | 2017-02-26 23:41:48 +0100 | [diff] [blame] | 1283 | return 0; |
Greg Kurz | 0e35a37 | 2017-02-26 23:42:10 +0100 | [diff] [blame] | 1284 | |
| 1285 | err: |
| 1286 | g_free(data); |
| 1287 | return -1; |
| 1288 | } |
| 1289 | |
| 1290 | static void local_cleanup(FsContext *ctx) |
| 1291 | { |
| 1292 | LocalData *data = ctx->private; |
| 1293 | |
| 1294 | close(data->mountfd); |
| 1295 | g_free(data); |
Aneesh Kumar K.V | 0174fe7 | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 1296 | } |
| 1297 | |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1298 | static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) |
| 1299 | { |
| 1300 | const char *sec_model = qemu_opt_get(opts, "security_model"); |
| 1301 | const char *path = qemu_opt_get(opts, "path"); |
Pradeep Jagadeesh | b8bbdb8 | 2017-02-28 10:31:46 +0100 | [diff] [blame] | 1302 | Error *err = NULL; |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1303 | |
| 1304 | if (!sec_model) { |
Greg Kurz | 63325b1 | 2016-01-22 15:12:17 +0100 | [diff] [blame] | 1305 | error_report("Security model not specified, local fs needs security model"); |
| 1306 | error_printf("valid options are:" |
| 1307 | "\tsecurity_model=[passthrough|mapped-xattr|mapped-file|none]\n"); |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1308 | return -1; |
| 1309 | } |
| 1310 | |
| 1311 | if (!strcmp(sec_model, "passthrough")) { |
| 1312 | fse->export_flags |= V9FS_SM_PASSTHROUGH; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 1313 | } else if (!strcmp(sec_model, "mapped") || |
| 1314 | !strcmp(sec_model, "mapped-xattr")) { |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1315 | fse->export_flags |= V9FS_SM_MAPPED; |
| 1316 | } else if (!strcmp(sec_model, "none")) { |
| 1317 | fse->export_flags |= V9FS_SM_NONE; |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 1318 | } else if (!strcmp(sec_model, "mapped-file")) { |
| 1319 | fse->export_flags |= V9FS_SM_MAPPED_FILE; |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1320 | } else { |
Greg Kurz | 63325b1 | 2016-01-22 15:12:17 +0100 | [diff] [blame] | 1321 | error_report("Invalid security model %s specified", sec_model); |
| 1322 | error_printf("valid options are:" |
| 1323 | "\t[passthrough|mapped-xattr|mapped-file|none]\n"); |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1324 | return -1; |
| 1325 | } |
| 1326 | |
| 1327 | if (!path) { |
Greg Kurz | 63325b1 | 2016-01-22 15:12:17 +0100 | [diff] [blame] | 1328 | error_report("fsdev: No path specified"); |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1329 | return -1; |
| 1330 | } |
Pradeep Jagadeesh | b8bbdb8 | 2017-02-28 10:31:46 +0100 | [diff] [blame] | 1331 | |
| 1332 | fsdev_throttle_parse_opts(opts, &fse->fst, &err); |
| 1333 | if (err) { |
| 1334 | error_reportf_err(err, "Throttle configuration is not valid: "); |
| 1335 | return -1; |
| 1336 | } |
| 1337 | |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1338 | fse->path = g_strdup(path); |
| 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
Anthony Liguori | 9f10751 | 2010-04-29 17:44:44 +0530 | [diff] [blame] | 1343 | FileOperations local_ops = { |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 1344 | .parse_opts = local_parse_opts, |
Aneesh Kumar K.V | 0174fe7 | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 1345 | .init = local_init, |
Greg Kurz | 0e35a37 | 2017-02-26 23:42:10 +0100 | [diff] [blame] | 1346 | .cleanup = local_cleanup, |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 1347 | .lstat = local_lstat, |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 1348 | .readlink = local_readlink, |
| 1349 | .close = local_close, |
| 1350 | .closedir = local_closedir, |
Anthony Liguori | a6568fe | 2010-04-29 17:44:55 +0530 | [diff] [blame] | 1351 | .open = local_open, |
| 1352 | .opendir = local_opendir, |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 1353 | .rewinddir = local_rewinddir, |
| 1354 | .telldir = local_telldir, |
Greg Kurz | 635324e | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 1355 | .readdir = local_readdir, |
Anthony Liguori | a923155 | 2010-04-29 17:44:56 +0530 | [diff] [blame] | 1356 | .seekdir = local_seekdir, |
Sanchit Garg | 56d15a5 | 2010-10-08 11:30:16 +0530 | [diff] [blame] | 1357 | .preadv = local_preadv, |
| 1358 | .pwritev = local_pwritev, |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 1359 | .chmod = local_chmod, |
| 1360 | .mknod = local_mknod, |
Anthony Liguori | c494dd6 | 2010-04-29 17:44:59 +0530 | [diff] [blame] | 1361 | .mkdir = local_mkdir, |
| 1362 | .fstat = local_fstat, |
| 1363 | .open2 = local_open2, |
| 1364 | .symlink = local_symlink, |
| 1365 | .link = local_link, |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1366 | .truncate = local_truncate, |
| 1367 | .rename = local_rename, |
| 1368 | .chown = local_chown, |
M. Mohan Kumar | 74bc02b | 2010-06-09 19:14:38 +0530 | [diff] [blame] | 1369 | .utimensat = local_utimensat, |
Anthony Liguori | 5bae190 | 2010-04-29 17:45:01 +0530 | [diff] [blame] | 1370 | .remove = local_remove, |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 1371 | .fsync = local_fsync, |
M. Mohan Kumar | be940c8 | 2010-05-10 12:11:03 +0530 | [diff] [blame] | 1372 | .statfs = local_statfs, |
Aneesh Kumar K.V | fa32ef8 | 2010-09-02 11:09:06 +0530 | [diff] [blame] | 1373 | .lgetxattr = local_lgetxattr, |
| 1374 | .llistxattr = local_llistxattr, |
Aneesh Kumar K.V | 10b468b | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 1375 | .lsetxattr = local_lsetxattr, |
Aneesh Kumar K.V | 9ed3ef2 | 2010-08-26 11:15:23 +0530 | [diff] [blame] | 1376 | .lremovexattr = local_lremovexattr, |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 1377 | .name_to_path = local_name_to_path, |
| 1378 | .renameat = local_renameat, |
| 1379 | .unlinkat = local_unlinkat, |
Anthony Liguori | 9f10751 | 2010-04-29 17:44:44 +0530 | [diff] [blame] | 1380 | }; |