9p-local.c 36.0 KB
Newer Older
1
/*
2
 * 9p Posix callback
3 4 5 6 7 8 9 10 11 12
 *
 * 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.
 *
 */
13

P
Peter Maydell 已提交
14
#include "qemu/osdep.h"
W
Wei Liu 已提交
15
#include "9p.h"
16
#include "9p-local.h"
17
#include "9p-xattr.h"
18
#include "9p-util.h"
19
#include "fsdev/qemu-fsdev.h"   /* local_ops */
20
#include <arpa/inet.h>
21 22
#include <pwd.h>
#include <grp.h>
23 24
#include <sys/socket.h>
#include <sys/un.h>
25
#include "qemu/xattr.h"
26
#include "qemu/cutils.h"
27
#include "qemu/error-report.h"
28
#include <libgen.h>
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <linux/fs.h>
#ifdef CONFIG_LINUX_MAGIC_H
#include <linux/magic.h>
#endif
#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
47

48 49 50 51
typedef struct {
    int mountfd;
} LocalData;

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags,
                        mode_t mode)
{
    LocalData *data = fs_ctx->private;

    /* All paths are relative to the path data->mountfd points to */
    while (*path == '/') {
        path++;
    }

    return relative_openat_nofollow(data->mountfd, path, flags, mode);
}

int local_opendir_nofollow(FsContext *fs_ctx, const char *path)
{
    return local_open_nofollow(fs_ctx, path, O_DIRECTORY | O_RDONLY, 0);
}

70 71 72 73 74 75 76 77
static void renameat_preserve_errno(int odirfd, const char *opath, int ndirfd,
                                    const char *npath)
{
    int serrno = errno;
    renameat(odirfd, opath, ndirfd, npath);
    errno = serrno;
}

78 79 80 81 82 83 84
static void unlinkat_preserve_errno(int dirfd, const char *path, int flags)
{
    int serrno = errno;
    unlinkat(dirfd, path, flags);
    errno = serrno;
}

85 86
#define VIRTFS_META_DIR ".virtfs_metadata"

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
static FILE *local_fopenat(int dirfd, const char *name, const char *mode)
{
    int fd, o_mode = 0;
    FILE *fp;
    int flags;
    /*
     * only supports two modes
     */
    if (mode[0] == 'r') {
        flags = O_RDONLY;
    } else if (mode[0] == 'w') {
        flags = O_WRONLY | O_TRUNC | O_CREAT;
        o_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    } else {
        return NULL;
    }
    fd = openat_file(dirfd, name, flags, o_mode);
    if (fd == -1) {
        return NULL;
    }
    fp = fdopen(fd, mode);
    if (!fp) {
        close(fd);
    }
    return fp;
}

114
#define ATTR_MAX 100
115
static void local_mapped_file_attr(int dirfd, const char *name,
116 117 118 119
                                   struct stat *stbuf)
{
    FILE *fp;
    char buf[ATTR_MAX];
120 121
    int map_dirfd;

122
    map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
123 124 125
    if (map_dirfd == -1) {
        return;
    }
126

127 128
    fp = local_fopenat(map_dirfd, name, "r");
    close_preserve_errno(map_dirfd);
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    if (!fp) {
        return;
    }
    memset(buf, 0, ATTR_MAX);
    while (fgets(buf, ATTR_MAX, fp)) {
        if (!strncmp(buf, "virtfs.uid", 10)) {
            stbuf->st_uid = atoi(buf+11);
        } else if (!strncmp(buf, "virtfs.gid", 10)) {
            stbuf->st_gid = atoi(buf+11);
        } else if (!strncmp(buf, "virtfs.mode", 11)) {
            stbuf->st_mode = atoi(buf+12);
        } else if (!strncmp(buf, "virtfs.rdev", 11)) {
            stbuf->st_rdev = atoi(buf+12);
        }
        memset(buf, 0, ATTR_MAX);
    }
    fclose(fp);
}

148
static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
149
{
150 151 152 153 154 155 156 157 158
    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;
    }
159

160
    err = fstatat(dirfd, name, stbuf, AT_SYMLINK_NOFOLLOW);
161
    if (err) {
162
        goto err_out;
163
    }
164
    if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
165 166 167 168 169
        /* Actual credentials are part of extended attrs */
        uid_t tmp_uid;
        gid_t tmp_gid;
        mode_t tmp_mode;
        dev_t tmp_dev;
170 171 172

        if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.uid", &tmp_uid,
                                 sizeof(uid_t)) > 0) {
173
            stbuf->st_uid = le32_to_cpu(tmp_uid);
174
        }
175 176
        if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.gid", &tmp_gid,
                                 sizeof(gid_t)) > 0) {
177
            stbuf->st_gid = le32_to_cpu(tmp_gid);
178
        }
179 180
        if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.mode", &tmp_mode,
                                 sizeof(mode_t)) > 0) {
181
            stbuf->st_mode = le32_to_cpu(tmp_mode);
182
        }
183 184
        if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.rdev", &tmp_dev,
                                 sizeof(dev_t)) > 0) {
185
            stbuf->st_rdev = le64_to_cpu(tmp_dev);
186
        }
187
    } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
188
        local_mapped_file_attr(dirfd, name, stbuf);
189
    }
190 191

err_out:
192 193 194 195
    close_preserve_errno(dirfd);
out:
    g_free(name);
    g_free(dirpath);
196 197 198
    return err;
}

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
static int local_set_mapped_file_attrat(int dirfd, const char *name,
                                        FsCred *credp)
{
    FILE *fp;
    int ret;
    char buf[ATTR_MAX];
    int uid = -1, gid = -1, mode = -1, rdev = -1;
    int map_dirfd;

    ret = mkdirat(dirfd, VIRTFS_META_DIR, 0700);
    if (ret < 0 && errno != EEXIST) {
        return -1;
    }

    map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
    if (map_dirfd == -1) {
        return -1;
    }

    fp = local_fopenat(map_dirfd, name, "r");
    if (!fp) {
        if (errno == ENOENT) {
            goto update_map_file;
        } else {
            close_preserve_errno(map_dirfd);
            return -1;
        }
    }
    memset(buf, 0, ATTR_MAX);
    while (fgets(buf, ATTR_MAX, fp)) {
        if (!strncmp(buf, "virtfs.uid", 10)) {
            uid = atoi(buf + 11);
        } else if (!strncmp(buf, "virtfs.gid", 10)) {
            gid = atoi(buf + 11);
        } else if (!strncmp(buf, "virtfs.mode", 11)) {
            mode = atoi(buf + 12);
        } else if (!strncmp(buf, "virtfs.rdev", 11)) {
            rdev = atoi(buf + 12);
        }
        memset(buf, 0, ATTR_MAX);
    }
    fclose(fp);

update_map_file:
    fp = local_fopenat(map_dirfd, name, "w");
    close_preserve_errno(map_dirfd);
    if (!fp) {
        return -1;
    }

    if (credp->fc_uid != -1) {
        uid = credp->fc_uid;
    }
    if (credp->fc_gid != -1) {
        gid = credp->fc_gid;
    }
    if (credp->fc_mode != -1) {
        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);

    return 0;
}

static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)
{
    int fd, ret;

    /* FIXME: this should be handled with fchmodat(AT_SYMLINK_NOFOLLOW).
     * Unfortunately, the linux kernel doesn't implement it yet. As an
     * alternative, let's open the file and use fchmod() instead. This
     * may fail depending on the permissions of the file, but it is the
     * best we can do to avoid TOCTTOU. We first try to open read-only
     * in case name points to a directory. If that fails, we try write-only
     * in case name doesn't point to a directory.
     */
    fd = openat_file(dirfd, name, O_RDONLY, 0);
    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);
    close_preserve_errno(fd);
    return ret;
}

static int local_set_xattrat(int dirfd, const char *path, FsCred *credp)
{
    int err;

    if (credp->fc_uid != -1) {
        uint32_t tmp_uid = cpu_to_le32(credp->fc_uid);
        err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.uid", &tmp_uid,
                                   sizeof(uid_t), 0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_gid != -1) {
        uint32_t tmp_gid = cpu_to_le32(credp->fc_gid);
        err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.gid", &tmp_gid,
                                   sizeof(gid_t), 0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_mode != -1) {
        uint32_t tmp_mode = cpu_to_le32(credp->fc_mode);
        err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.mode", &tmp_mode,
                                   sizeof(mode_t), 0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_rdev != -1) {
        uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev);
        err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.rdev", &tmp_rdev,
                                   sizeof(dev_t), 0);
        if (err) {
            return err;
        }
    }
    return 0;
}

348 349 350 351
static int local_set_cred_passthrough(FsContext *fs_ctx, int dirfd,
                                      const char *name, FsCred *credp)
{
    if (fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
352
                 AT_SYMLINK_NOFOLLOW) < 0) {
353 354 355 356 357 358 359 360 361 362 363 364
        /*
         * If we fail to change ownership and if we are
         * using security model none. Ignore the error
         */
        if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
            return -1;
        }
    }

    return fchmodat_nofollow(dirfd, name, credp->fc_mode & 07777);
}

365 366
static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
                              char *buf, size_t bufsz)
367
{
368
    ssize_t tsize = -1;
369

370 371
    if ((fs_ctx->export_flags & V9FS_SM_MAPPED) ||
        (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
372
        int fd;
373 374

        fd = local_open_nofollow(fs_ctx, fs_path->data, O_RDONLY, 0);
375 376 377 378 379 380
        if (fd == -1) {
            return -1;
        }
        do {
            tsize = read(fd, (void *)buf, bufsz);
        } while (tsize == -1 && errno == EINTR);
381
        close_preserve_errno(fd);
382 383
    } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
               (fs_ctx->export_flags & V9FS_SM_NONE)) {
384 385 386 387 388 389 390 391 392 393 394 395 396 397
        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);
398 399
    }
    return tsize;
400 401
}

402
static int local_close(FsContext *ctx, V9fsFidOpenState *fs)
403
{
404
    return close(fs->fd);
405 406
}

407
static int local_closedir(FsContext *ctx, V9fsFidOpenState *fs)
408
{
G
Greg Kurz 已提交
409
    return closedir(fs->dir.stream);
410
}
411

412 413
static int local_open(FsContext *ctx, V9fsPath *fs_path,
                      int flags, V9fsFidOpenState *fs)
414
{
415
    int fd;
416

417
    fd = local_open_nofollow(ctx, fs_path->data, flags, 0);
418 419 420 421
    if (fd == -1) {
        return -1;
    }
    fs->fd = fd;
422
    return fs->fd;
423 424
}

425 426
static int local_opendir(FsContext *ctx,
                         V9fsPath *fs_path, V9fsFidOpenState *fs)
427
{
428
    int dirfd;
429
    DIR *stream;
430

431 432 433 434 435 436
    dirfd = local_opendir_nofollow(ctx, fs_path->data);
    if (dirfd == -1) {
        return -1;
    }

    stream = fdopendir(dirfd);
437
    if (!stream) {
G
Greg Kurz 已提交
438
        close(dirfd);
439 440
        return -1;
    }
441
    fs->dir.stream = stream;
442
    return 0;
443 444
}

445
static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs)
446
{
G
Greg Kurz 已提交
447
    rewinddir(fs->dir.stream);
448 449
}

450
static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs)
451
{
G
Greg Kurz 已提交
452
    return telldir(fs->dir.stream);
453 454
}

G
Greg Kurz 已提交
455
static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs)
456
{
G
Greg Kurz 已提交
457
    struct dirent *entry;
458 459

again:
G
Greg Kurz 已提交
460 461 462 463 464
    entry = readdir(fs->dir.stream);
    if (!entry) {
        return NULL;
    }

465 466 467
    if (ctx->export_flags & V9FS_SM_MAPPED) {
        entry->d_type = DT_UNKNOWN;
    } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
G
Greg Kurz 已提交
468
        if (!strcmp(entry->d_name, VIRTFS_META_DIR)) {
469 470 471
            /* skp the meta data directory */
            goto again;
        }
472
        entry->d_type = DT_UNKNOWN;
473
    }
G
Greg Kurz 已提交
474 475

    return entry;
476 477
}

478
static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
479
{
G
Greg Kurz 已提交
480
    seekdir(fs->dir.stream, off);
481 482
}

483 484
static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs,
                            const struct iovec *iov,
485
                            int iovcnt, off_t offset)
486
{
487
#ifdef CONFIG_PREADV
488
    return preadv(fs->fd, iov, iovcnt, offset);
489
#else
490
    int err = lseek(fs->fd, offset, SEEK_SET);
491 492 493
    if (err == -1) {
        return err;
    } else {
494
        return readv(fs->fd, iov, iovcnt);
495 496
    }
#endif
497 498
}

499 500
static ssize_t local_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
                             const struct iovec *iov,
501
                             int iovcnt, off_t offset)
502
{
503 504
    ssize_t ret
;
505
#ifdef CONFIG_PREADV
506
    ret = pwritev(fs->fd, iov, iovcnt, offset);
507
#else
508
    int err = lseek(fs->fd, offset, SEEK_SET);
509 510 511
    if (err == -1) {
        return err;
    } else {
512
        ret = writev(fs->fd, iov, iovcnt);
513 514
    }
#endif
515 516 517 518 519 520 521
#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
         * after write when writeout=immediate is sepcified.
         */
522
        sync_file_range(fs->fd, offset, ret,
523 524 525 526
                        SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE);
    }
#endif
    return ret;
527 528
}

529
static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
530
{
531 532
    char *dirpath = g_path_get_dirname(fs_path->data);
    char *name = g_path_get_basename(fs_path->data);
533
    int ret = -1;
534 535 536 537 538 539
    int dirfd;

    dirfd = local_opendir_nofollow(fs_ctx, dirpath);
    if (dirfd == -1) {
        goto out;
    }
540

541
    if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
542
        ret = local_set_xattrat(dirfd, name, credp);
543
    } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
544 545 546 547
        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);
548
    }
549 550 551 552 553
    close_preserve_errno(dirfd);

out:
    g_free(dirpath);
    g_free(name);
554
    return ret;
555 556
}

557 558
static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
                       const char *name, FsCred *credp)
559
{
560
    int err = -1;
561
    int dirfd;
562

563 564 565 566
    dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
    if (dirfd == -1) {
        return -1;
    }
567

568 569 570
    if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
        fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
        err = mknodat(dirfd, name, SM_LOCAL_MODE_BITS | S_IFREG, 0);
571
        if (err == -1) {
572
            goto out;
573
        }
574

575 576 577 578
        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);
579 580 581 582
        }
        if (err == -1) {
            goto err_end;
        }
583 584 585
    } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
               fs_ctx->export_flags & V9FS_SM_NONE) {
        err = mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev);
586
        if (err == -1) {
587
            goto out;
588
        }
589
        err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
590 591 592 593
        if (err == -1) {
            goto err_end;
        }
    }
594
    goto out;
595 596

err_end:
597
    unlinkat_preserve_errno(dirfd, name, 0);
598
out:
599
    close_preserve_errno(dirfd);
600
    return err;
601 602
}

603 604
static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
                       const char *name, FsCred *credp)
605
{
606
    int err = -1;
607
    int dirfd;
608

609 610 611 612
    dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
    if (dirfd == -1) {
        return -1;
    }
613

614 615 616
    if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
        fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
        err = mkdirat(dirfd, name, SM_LOCAL_DIR_MODE_BITS);
617
        if (err == -1) {
618
            goto out;
619
        }
620 621 622 623 624 625
        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);
626 627 628 629
        }
        if (err == -1) {
            goto err_end;
        }
630 631 632
    } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
               fs_ctx->export_flags & V9FS_SM_NONE) {
        err = mkdirat(dirfd, name, credp->fc_mode);
633
        if (err == -1) {
634
            goto out;
635
        }
636
        err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
637 638 639 640
        if (err == -1) {
            goto err_end;
        }
    }
641
    goto out;
642 643

err_end:
644
    unlinkat_preserve_errno(dirfd, name, AT_REMOVEDIR);
645
out:
646
    close_preserve_errno(dirfd);
647
    return err;
648 649
}

650
static int local_fstat(FsContext *fs_ctx, int fid_type,
651
                       V9fsFidOpenState *fs, struct stat *stbuf)
652
{
653 654 655
    int err, fd;

    if (fid_type == P9_FID_DIR) {
G
Greg Kurz 已提交
656
        fd = dirfd(fs->dir.stream);
657 658 659 660 661
    } else {
        fd = fs->fd;
    }

    err = fstat(fd, stbuf);
662 663 664
    if (err) {
        return err;
    }
665
    if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
666 667 668 669 670 671
        /* Actual credentials are part of extended attrs */
        uid_t tmp_uid;
        gid_t tmp_gid;
        mode_t tmp_mode;
        dev_t tmp_dev;

672 673
        if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) {
            stbuf->st_uid = le32_to_cpu(tmp_uid);
674
        }
675 676
        if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) {
            stbuf->st_gid = le32_to_cpu(tmp_gid);
677
        }
678 679
        if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) {
            stbuf->st_mode = le32_to_cpu(tmp_mode);
680
        }
681 682
        if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) {
            stbuf->st_rdev = le64_to_cpu(tmp_dev);
683
        }
684 685 686
    } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
        errno = EOPNOTSUPP;
        return -1;
687 688
    }
    return err;
689 690
}

691
static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
692
                       int flags, FsCred *credp, V9fsFidOpenState *fs)
693
{
694 695
    int fd = -1;
    int err = -1;
696
    int dirfd;
697

698 699 700 701 702
    /*
     * Mark all the open to not follow symlinks
     */
    flags |= O_NOFOLLOW;

703 704 705 706
    dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
    if (dirfd == -1) {
        return -1;
    }
707

708
    /* Determine the security model */
709 710 711
    if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
        fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
        fd = openat_file(dirfd, name, flags, SM_LOCAL_MODE_BITS);
712
        if (fd == -1) {
713
            goto out;
714 715
        }
        credp->fc_mode = credp->fc_mode|S_IFREG;
716 717 718 719 720
        if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
            /* Set cleint credentials in xattr */
            err = local_set_xattrat(dirfd, name, credp);
        } else {
            err = local_set_mapped_file_attrat(dirfd, name, credp);
721 722 723 724
        }
        if (err == -1) {
            goto err_end;
        }
725 726
    } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
               (fs_ctx->export_flags & V9FS_SM_NONE)) {
727
        fd = openat_file(dirfd, name, flags, credp->fc_mode);
728
        if (fd == -1) {
729
            goto out;
730
        }
731
        err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
732 733 734 735
        if (err == -1) {
            goto err_end;
        }
    }
736
    err = fd;
737
    fs->fd = fd;
738
    goto out;
739 740

err_end:
741 742 743
    unlinkat_preserve_errno(dirfd, name,
                            flags & O_DIRECTORY ? AT_REMOVEDIR : 0);
    close_preserve_errno(fd);
744
out:
745
    close_preserve_errno(dirfd);
746
    return err;
747 748
}

749

750
static int local_symlink(FsContext *fs_ctx, const char *oldpath,
751
                         V9fsPath *dir_path, const char *name, FsCred *credp)
752
{
753
    int err = -1;
754
    int dirfd;
755

756 757 758 759
    dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
    if (dirfd == -1) {
        return -1;
    }
760

761
    /* Determine the security model */
762 763
    if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
        fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
764 765
        int fd;
        ssize_t oldpath_size, write_size;
766 767 768

        fd = openat_file(dirfd, name, O_CREAT | O_EXCL | O_RDWR,
                         SM_LOCAL_MODE_BITS);
769
        if (fd == -1) {
770
            goto out;
771 772
        }
        /* Write the oldpath (target) to the file. */
773
        oldpath_size = strlen(oldpath);
774 775 776
        do {
            write_size = write(fd, (void *)oldpath, oldpath_size);
        } while (write_size == -1 && errno == EINTR);
777
        close_preserve_errno(fd);
778 779 780 781 782

        if (write_size != oldpath_size) {
            goto err_end;
        }
        /* Set cleint credentials in symlink's xattr */
783
        credp->fc_mode = credp->fc_mode | S_IFLNK;
784

785 786 787 788
        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);
789 790 791 792
        }
        if (err == -1) {
            goto err_end;
        }
793 794 795
    } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
               fs_ctx->export_flags & V9FS_SM_NONE) {
        err = symlinkat(oldpath, dirfd, name);
796
        if (err) {
797
            goto out;
798
        }
799 800
        err = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
                       AT_SYMLINK_NOFOLLOW);
801
        if (err == -1) {
802 803 804 805
            /*
             * If we fail to change ownership and if we are
             * using security model none. Ignore the error
             */
806
            if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
807
                goto err_end;
808
            } else {
809
                err = 0;
810
            }
811 812
        }
    }
813
    goto out;
814 815

err_end:
816
    unlinkat_preserve_errno(dirfd, name, 0);
817
out:
818
    close_preserve_errno(dirfd);
819
    return err;
820 821
}

822 823
static int local_link(FsContext *ctx, V9fsPath *oldpath,
                      V9fsPath *dirpath, const char *name)
824
{
825 826 827 828 829 830 831 832 833
    char *odirpath = g_path_get_dirname(oldpath->data);
    char *oname = g_path_get_basename(oldpath->data);
    int ret = -1;
    int odirfd, ndirfd;

    odirfd = local_opendir_nofollow(ctx, odirpath);
    if (odirfd == -1) {
        goto out;
    }
834

835 836 837 838 839
    ndirfd = local_opendir_nofollow(ctx, dirpath->data);
    if (ndirfd == -1) {
        close_preserve_errno(odirfd);
        goto out;
    }
840

841
    ret = linkat(odirfd, oname, ndirfd, name, 0);
842
    if (ret < 0) {
843
        goto out_close;
844
    }
845 846

    /* now link the virtfs_metadata files */
847
    if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
        int omap_dirfd, nmap_dirfd;

        ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700);
        if (ret < 0 && errno != EEXIST) {
            goto err_undo_link;
        }

        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);
869
        if (ret < 0 && errno != ENOENT) {
870
            goto err_undo_link;
871
        }
872 873

        ret = 0;
874
    }
875
    goto out_close;
876

877 878 879 880 881 882 883
err:
    ret = -1;
err_undo_link:
    unlinkat_preserve_errno(ndirfd, name, 0);
out_close:
    close_preserve_errno(ndirfd);
    close_preserve_errno(odirfd);
884
out:
885 886
    g_free(oname);
    g_free(odirpath);
887
    return ret;
888 889
}

890
static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size)
891
{
892
    int fd, ret;
893

894 895 896 897 898 899
    fd = local_open_nofollow(ctx, fs_path->data, O_WRONLY, 0);
    if (fd == -1) {
        return -1;
    }
    ret = ftruncate(fd, size);
    close_preserve_errno(fd);
900
    return ret;
901 902
}

903
static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
904
{
905 906
    char *dirpath = g_path_get_dirname(fs_path->data);
    char *name = g_path_get_basename(fs_path->data);
907
    int ret = -1;
908 909 910 911 912 913
    int dirfd;

    dirfd = local_opendir_nofollow(fs_ctx, dirpath);
    if (dirfd == -1) {
        goto out;
    }
914

915
    if ((credp->fc_uid == -1 && credp->fc_gid == -1) ||
916 917
        (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
        (fs_ctx->export_flags & V9FS_SM_NONE)) {
918 919
        ret = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
                       AT_SYMLINK_NOFOLLOW);
920
    } else if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
921
        ret = local_set_xattrat(dirfd, name, credp);
922
    } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
923
        ret = local_set_mapped_file_attrat(dirfd, name, credp);
924
    }
925 926 927 928 929

    close_preserve_errno(dirfd);
out:
    g_free(name);
    g_free(dirpath);
930
    return ret;
931 932
}

933
static int local_utimensat(FsContext *s, V9fsPath *fs_path,
934
                           const struct timespec *buf)
935
{
936 937 938
    char *dirpath = g_path_get_dirname(fs_path->data);
    char *name = g_path_get_basename(fs_path->data);
    int dirfd, ret = -1;
939

940 941 942 943 944 945 946 947 948 949
    dirfd = local_opendir_nofollow(s, dirpath);
    if (dirfd == -1) {
        goto out;
    }

    ret = utimensat(dirfd, name, buf, AT_SYMLINK_NOFOLLOW);
    close_preserve_errno(dirfd);
out:
    g_free(dirpath);
    g_free(name);
950
    return ret;
951 952
}

953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
                                 int flags)
{
    int ret = -1;

    if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
        int map_dirfd;

        if (flags == AT_REMOVEDIR) {
            int fd;

            fd = openat(dirfd, name, O_RDONLY | O_DIRECTORY | O_PATH);
            if (fd == -1) {
                goto err_out;
            }
            /*
             * If directory remove .virtfs_metadata contained in the
             * directory
             */
            ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
            close_preserve_errno(fd);
            if (ret < 0 && errno != ENOENT) {
                /*
                 * We didn't had the .virtfs_metadata file. May be file created
                 * in non-mapped mode ?. Ignore ENOENT.
                 */
                goto err_out;
            }
        }
        /*
         * Now remove the name from parent directory
         * .virtfs_metadata directory.
         */
        map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
        ret = unlinkat(map_dirfd, name, 0);
        close_preserve_errno(map_dirfd);
        if (ret < 0 && errno != ENOENT) {
            /*
             * We didn't had the .virtfs_metadata file. May be file created
             * in non-mapped mode ?. Ignore ENOENT.
             */
            goto err_out;
        }
    }

    ret = unlinkat(dirfd, name, flags);
err_out:
    return ret;
}

1003 1004
static int local_remove(FsContext *ctx, const char *path)
{
1005
    struct stat stbuf;
1006 1007 1008 1009 1010
    char *dirpath = g_path_get_dirname(path);
    char *name = g_path_get_basename(path);
    int flags = 0;
    int dirfd;
    int err = -1;
1011

1012
    dirfd = local_opendir_nofollow(ctx, dirpath);
1013
    if (dirfd == -1) {
1014
        goto out;
1015
    }
1016

1017 1018 1019 1020 1021 1022 1023 1024 1025
    if (fstatat(dirfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0) {
        goto err_out;
    }

    if (S_ISDIR(stbuf.st_mode)) {
        flags |= AT_REMOVEDIR;
    }

    err = local_unlinkat_common(ctx, dirfd, name, flags);
1026
err_out:
1027 1028 1029 1030
    close_preserve_errno(dirfd);
out:
    g_free(name);
    g_free(dirpath);
1031
    return err;
1032 1033
}

1034 1035
static int local_fsync(FsContext *ctx, int fid_type,
                       V9fsFidOpenState *fs, int datasync)
1036
{
1037 1038 1039
    int fd;

    if (fid_type == P9_FID_DIR) {
G
Greg Kurz 已提交
1040
        fd = dirfd(fs->dir.stream);
1041 1042 1043 1044
    } else {
        fd = fs->fd;
    }

1045
    if (datasync) {
1046
        return qemu_fdatasync(fd);
1047
    } else {
1048
        return fsync(fd);
1049
    }
1050 1051
}

1052
static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
1053
{
1054
    int fd, ret;
1055

1056
    fd = local_open_nofollow(s, fs_path->data, O_RDONLY, 0);
G
Greg Kurz 已提交
1057 1058 1059
    if (fd == -1) {
        return -1;
    }
1060 1061
    ret = fstatfs(fd, stbuf);
    close_preserve_errno(fd);
1062
    return ret;
1063 1064
}

1065
static ssize_t local_lgetxattr(FsContext *ctx, V9fsPath *fs_path,
1066 1067
                               const char *name, void *value, size_t size)
{
1068 1069
    char *path = fs_path->data;

1070
    return v9fs_get_xattr(ctx, path, name, value, size);
1071 1072
}

1073
static ssize_t local_llistxattr(FsContext *ctx, V9fsPath *fs_path,
1074 1075
                                void *value, size_t size)
{
1076 1077
    char *path = fs_path->data;

1078
    return v9fs_list_xattr(ctx, path, value, size);
1079 1080
}

1081
static int local_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name,
1082 1083
                           void *value, size_t size, int flags)
{
1084 1085
    char *path = fs_path->data;

1086
    return v9fs_set_xattr(ctx, path, name, value, size, flags);
1087 1088
}

1089 1090
static int local_lremovexattr(FsContext *ctx, V9fsPath *fs_path,
                              const char *name)
1091
{
1092 1093
    char *path = fs_path->data;

1094
    return v9fs_remove_xattr(ctx, path, name);
1095 1096
}

1097 1098 1099 1100
static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path,
                              const char *name, V9fsPath *target)
{
    if (dir_path) {
1101
        v9fs_path_sprintf(target, "%s/%s", dir_path->data, name);
1102
    } else {
1103
        v9fs_path_sprintf(target, "%s", name);
1104 1105 1106 1107 1108 1109 1110 1111 1112
    }
    return 0;
}

static int local_renameat(FsContext *ctx, V9fsPath *olddir,
                          const char *old_name, V9fsPath *newdir,
                          const char *new_name)
{
    int ret;
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
    int odirfd, ndirfd;

    odirfd = local_opendir_nofollow(ctx, olddir->data);
    if (odirfd == -1) {
        return -1;
    }

    ndirfd = local_opendir_nofollow(ctx, newdir->data);
    if (ndirfd == -1) {
        close_preserve_errno(odirfd);
        return -1;
    }

    ret = renameat(odirfd, old_name, ndirfd, new_name);
    if (ret < 0) {
        goto out;
    }
1130

1131 1132
    if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
        int omap_dirfd, nmap_dirfd;
1133

1134 1135 1136 1137
        ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700);
        if (ret < 0 && errno != EEXIST) {
            goto err_undo_rename;
        }
1138

1139
        omap_dirfd = openat_dir(odirfd, VIRTFS_META_DIR);
1140 1141 1142 1143
        if (omap_dirfd == -1) {
            goto err;
        }

1144
        nmap_dirfd = openat_dir(ndirfd, VIRTFS_META_DIR);
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
        if (nmap_dirfd == -1) {
            close_preserve_errno(omap_dirfd);
            goto err;
        }

        /* rename the .virtfs_metadata files */
        ret = renameat(omap_dirfd, old_name, nmap_dirfd, new_name);
        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);
1169 1170 1171
    return ret;
}

G
Greg Kurz 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
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;
}

1199 1200 1201 1202
static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
                          const char *name, int flags)
{
    int ret;
1203
    int dirfd;
1204

1205 1206 1207
    dirfd = local_opendir_nofollow(ctx, dir->data);
    if (dirfd == -1) {
        return -1;
1208
    }
1209

1210 1211
    ret = local_unlinkat_common(ctx, dirfd, name, flags);
    close_preserve_errno(dirfd);
1212 1213
    return ret;
}
1214

1215 1216 1217
static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
                                mode_t st_mode, uint64_t *st_gen)
{
1218
#ifdef FS_IOC_GETVERSION
1219
    int err;
1220 1221
    V9fsFidOpenState fid_open;

1222 1223 1224 1225 1226
    /*
     * 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)) {
1227 1228
        errno = ENOTTY;
        return -1;
1229
    }
1230 1231 1232
    err = local_open(ctx, path, O_RDONLY, &fid_open);
    if (err < 0) {
        return err;
1233
    }
1234 1235
    err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
    local_close(ctx, &fid_open);
1236
    return err;
1237
#else
1238 1239
    errno = ENOTTY;
    return -1;
1240
#endif
1241 1242
}

1243 1244
static int local_init(FsContext *ctx)
{
1245
    struct statfs stbuf;
1246 1247 1248 1249 1250 1251
    LocalData *data = g_malloc(sizeof(*data));

    data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY);
    if (data->mountfd == -1) {
        goto err;
    }
1252

1253 1254 1255 1256
#ifdef FS_IOC_GETVERSION
    /*
     * use ioc_getversion only if the ioctl is definied
     */
1257 1258 1259
    if (fstatfs(data->mountfd, &stbuf) < 0) {
        close_preserve_errno(data->mountfd);
        goto err;
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
    }
    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

1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
    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;
    }
1284
    ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT;
1285

1286
    ctx->private = data;
1287
    return 0;
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299

err:
    g_free(data);
    return -1;
}

static void local_cleanup(FsContext *ctx)
{
    LocalData *data = ctx->private;

    close(data->mountfd);
    g_free(data);
1300 1301
}

1302 1303 1304 1305 1306 1307
static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
{
    const char *sec_model = qemu_opt_get(opts, "security_model");
    const char *path = qemu_opt_get(opts, "path");

    if (!sec_model) {
1308 1309 1310
        error_report("Security model not specified, local fs needs security model");
        error_printf("valid options are:"
                     "\tsecurity_model=[passthrough|mapped-xattr|mapped-file|none]\n");
1311 1312 1313 1314 1315
        return -1;
    }

    if (!strcmp(sec_model, "passthrough")) {
        fse->export_flags |= V9FS_SM_PASSTHROUGH;
1316 1317
    } else if (!strcmp(sec_model, "mapped") ||
               !strcmp(sec_model, "mapped-xattr")) {
1318 1319 1320
        fse->export_flags |= V9FS_SM_MAPPED;
    } else if (!strcmp(sec_model, "none")) {
        fse->export_flags |= V9FS_SM_NONE;
1321 1322
    } else if (!strcmp(sec_model, "mapped-file")) {
        fse->export_flags |= V9FS_SM_MAPPED_FILE;
1323
    } else {
1324 1325 1326
        error_report("Invalid security model %s specified", sec_model);
        error_printf("valid options are:"
                     "\t[passthrough|mapped-xattr|mapped-file|none]\n");
1327 1328 1329 1330
        return -1;
    }

    if (!path) {
1331
        error_report("fsdev: No path specified");
1332 1333 1334 1335 1336 1337 1338
        return -1;
    }
    fse->path = g_strdup(path);

    return 0;
}

1339
FileOperations local_ops = {
1340
    .parse_opts = local_parse_opts,
1341
    .init  = local_init,
1342
    .cleanup = local_cleanup,
1343 1344 1345 1346
    .lstat = local_lstat,
    .readlink = local_readlink,
    .close = local_close,
    .closedir = local_closedir,
1347 1348
    .open = local_open,
    .opendir = local_opendir,
1349 1350
    .rewinddir = local_rewinddir,
    .telldir = local_telldir,
G
Greg Kurz 已提交
1351
    .readdir = local_readdir,
1352
    .seekdir = local_seekdir,
1353 1354
    .preadv = local_preadv,
    .pwritev = local_pwritev,
1355 1356 1357 1358 1359 1360 1361
    .chmod = local_chmod,
    .mknod = local_mknod,
    .mkdir = local_mkdir,
    .fstat = local_fstat,
    .open2 = local_open2,
    .symlink = local_symlink,
    .link = local_link,
1362 1363 1364
    .truncate = local_truncate,
    .rename = local_rename,
    .chown = local_chown,
M
M. Mohan Kumar 已提交
1365
    .utimensat = local_utimensat,
1366
    .remove = local_remove,
1367
    .fsync = local_fsync,
1368
    .statfs = local_statfs,
1369 1370
    .lgetxattr = local_lgetxattr,
    .llistxattr = local_llistxattr,
1371
    .lsetxattr = local_lsetxattr,
1372
    .lremovexattr = local_lremovexattr,
1373 1374 1375
    .name_to_path = local_name_to_path,
    .renameat  = local_renameat,
    .unlinkat = local_unlinkat,
1376
};