xref: /openbmc/qemu/hw/9pfs/9p-local.c (revision 795c40b8)
1 /*
2  * 9p Posix callback
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  */
13 
14 #include "qemu/osdep.h"
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 #include <pwd.h>
22 #include <grp.h>
23 #include <sys/socket.h>
24 #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 #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
47 
48 typedef struct {
49     int mountfd;
50 } LocalData;
51 
52 int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags,
53                         mode_t mode)
54 {
55     LocalData *data = fs_ctx->private;
56 
57     /* All paths are relative to the path data->mountfd points to */
58     while (*path == '/') {
59         path++;
60     }
61 
62     return relative_openat_nofollow(data->mountfd, path, flags, mode);
63 }
64 
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 
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 
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 
85 #define VIRTFS_META_DIR ".virtfs_metadata"
86 
87 static FILE *local_fopenat(int dirfd, const char *name, const char *mode)
88 {
89     int fd, o_mode = 0;
90     FILE *fp;
91     int flags;
92     /*
93      * only supports two modes
94      */
95     if (mode[0] == 'r') {
96         flags = O_RDONLY;
97     } else if (mode[0] == 'w') {
98         flags = O_WRONLY | O_TRUNC | O_CREAT;
99         o_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
100     } else {
101         return NULL;
102     }
103     fd = openat_file(dirfd, name, flags, o_mode);
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 
114 #define ATTR_MAX 100
115 static void local_mapped_file_attr(int dirfd, const char *name,
116                                    struct stat *stbuf)
117 {
118     FILE *fp;
119     char buf[ATTR_MAX];
120     int map_dirfd;
121 
122     map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
123     if (map_dirfd == -1) {
124         return;
125     }
126 
127     fp = local_fopenat(map_dirfd, name, "r");
128     close_preserve_errno(map_dirfd);
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 
148 static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
149 {
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;
154 
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);
161     if (err) {
162         goto err_out;
163     }
164     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
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;
170 
171         if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.uid", &tmp_uid,
172                                  sizeof(uid_t)) > 0) {
173             stbuf->st_uid = le32_to_cpu(tmp_uid);
174         }
175         if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.gid", &tmp_gid,
176                                  sizeof(gid_t)) > 0) {
177             stbuf->st_gid = le32_to_cpu(tmp_gid);
178         }
179         if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.mode", &tmp_mode,
180                                  sizeof(mode_t)) > 0) {
181             stbuf->st_mode = le32_to_cpu(tmp_mode);
182         }
183         if (fgetxattrat_nofollow(dirfd, name, "user.virtfs.rdev", &tmp_dev,
184                                  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     close_preserve_errno(dirfd);
193 out:
194     g_free(name);
195     g_free(dirpath);
196     return err;
197 }
198 
199 static int local_set_mapped_file_attrat(int dirfd, const char *name,
200                                         FsCred *credp)
201 {
202     FILE *fp;
203     int ret;
204     char buf[ATTR_MAX];
205     int uid = -1, gid = -1, mode = -1, rdev = -1;
206     int map_dirfd;
207 
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");
219     if (!fp) {
220         if (errno == ENOENT) {
221             goto update_map_file;
222         } else {
223             close_preserve_errno(map_dirfd);
224             return -1;
225         }
226     }
227     memset(buf, 0, ATTR_MAX);
228     while (fgets(buf, ATTR_MAX, fp)) {
229         if (!strncmp(buf, "virtfs.uid", 10)) {
230             uid = atoi(buf + 11);
231         } else if (!strncmp(buf, "virtfs.gid", 10)) {
232             gid = atoi(buf + 11);
233         } else if (!strncmp(buf, "virtfs.mode", 11)) {
234             mode = atoi(buf + 12);
235         } else if (!strncmp(buf, "virtfs.rdev", 11)) {
236             rdev = atoi(buf + 12);
237         }
238         memset(buf, 0, ATTR_MAX);
239     }
240     fclose(fp);
241 
242 update_map_file:
243     fp = local_fopenat(map_dirfd, name, "w");
244     close_preserve_errno(map_dirfd);
245     if (!fp) {
246         return -1;
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 
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 
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);
306     return ret;
307 }
308 
309 static int local_set_xattrat(int dirfd, const char *path, FsCred *credp)
310 {
311     int err;
312 
313     if (credp->fc_uid != -1) {
314         uint32_t tmp_uid = cpu_to_le32(credp->fc_uid);
315         err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.uid", &tmp_uid,
316                                    sizeof(uid_t), 0);
317         if (err) {
318             return err;
319         }
320     }
321     if (credp->fc_gid != -1) {
322         uint32_t tmp_gid = cpu_to_le32(credp->fc_gid);
323         err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.gid", &tmp_gid,
324                                    sizeof(gid_t), 0);
325         if (err) {
326             return err;
327         }
328     }
329     if (credp->fc_mode != -1) {
330         uint32_t tmp_mode = cpu_to_le32(credp->fc_mode);
331         err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.mode", &tmp_mode,
332                                    sizeof(mode_t), 0);
333         if (err) {
334             return err;
335         }
336     }
337     if (credp->fc_rdev != -1) {
338         uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev);
339         err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.rdev", &tmp_rdev,
340                                    sizeof(dev_t), 0);
341         if (err) {
342             return err;
343         }
344     }
345     return 0;
346 }
347 
348 static int local_set_cred_passthrough(FsContext *fs_ctx, int dirfd,
349                                       const char *name, FsCred *credp)
350 {
351     if (fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
352                  AT_SYMLINK_NOFOLLOW) < 0) {
353         /*
354          * If we fail to change ownership and if we are
355          * using security model none. Ignore the error
356          */
357         if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
358             return -1;
359         }
360     }
361 
362     return fchmodat_nofollow(dirfd, name, credp->fc_mode & 07777);
363 }
364 
365 static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
366                               char *buf, size_t bufsz)
367 {
368     ssize_t tsize = -1;
369 
370     if ((fs_ctx->export_flags & V9FS_SM_MAPPED) ||
371         (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         if (fd == -1) {
376             return -1;
377         }
378         do {
379             tsize = read(fd, (void *)buf, bufsz);
380         } while (tsize == -1 && errno == EINTR);
381         close_preserve_errno(fd);
382     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
383                (fs_ctx->export_flags & V9FS_SM_NONE)) {
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);
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 {
409     return closedir(fs->dir.stream);
410 }
411 
412 static int local_open(FsContext *ctx, V9fsPath *fs_path,
413                       int flags, V9fsFidOpenState *fs)
414 {
415     int fd;
416 
417     fd = local_open_nofollow(ctx, fs_path->data, flags, 0);
418     if (fd == -1) {
419         return -1;
420     }
421     fs->fd = fd;
422     return fs->fd;
423 }
424 
425 static int local_opendir(FsContext *ctx,
426                          V9fsPath *fs_path, V9fsFidOpenState *fs)
427 {
428     int dirfd;
429     DIR *stream;
430 
431     dirfd = local_opendir_nofollow(ctx, fs_path->data);
432     if (dirfd == -1) {
433         return -1;
434     }
435 
436     stream = fdopendir(dirfd);
437     if (!stream) {
438         close(dirfd);
439         return -1;
440     }
441     fs->dir.stream = stream;
442     return 0;
443 }
444 
445 static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs)
446 {
447     rewinddir(fs->dir.stream);
448 }
449 
450 static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs)
451 {
452     return telldir(fs->dir.stream);
453 }
454 
455 static bool local_is_mapped_file_metadata(FsContext *fs_ctx, const char *name)
456 {
457     return !strcmp(name, VIRTFS_META_DIR);
458 }
459 
460 static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs)
461 {
462     struct dirent *entry;
463 
464 again:
465     entry = readdir(fs->dir.stream);
466     if (!entry) {
467         return NULL;
468     }
469 
470     if (ctx->export_flags & V9FS_SM_MAPPED) {
471         entry->d_type = DT_UNKNOWN;
472     } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
473         if (local_is_mapped_file_metadata(ctx, entry->d_name)) {
474             /* skip the meta data directory */
475             goto again;
476         }
477         entry->d_type = DT_UNKNOWN;
478     }
479 
480     return entry;
481 }
482 
483 static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
484 {
485     seekdir(fs->dir.stream, off);
486 }
487 
488 static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs,
489                             const struct iovec *iov,
490                             int iovcnt, off_t offset)
491 {
492 #ifdef CONFIG_PREADV
493     return preadv(fs->fd, iov, iovcnt, offset);
494 #else
495     int err = lseek(fs->fd, offset, SEEK_SET);
496     if (err == -1) {
497         return err;
498     } else {
499         return readv(fs->fd, iov, iovcnt);
500     }
501 #endif
502 }
503 
504 static ssize_t local_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
505                              const struct iovec *iov,
506                              int iovcnt, off_t offset)
507 {
508     ssize_t ret;
509 #ifdef CONFIG_PREADV
510     ret = pwritev(fs->fd, iov, iovcnt, offset);
511 #else
512     int err = lseek(fs->fd, offset, SEEK_SET);
513     if (err == -1) {
514         return err;
515     } else {
516         ret = writev(fs->fd, iov, iovcnt);
517     }
518 #endif
519 #ifdef CONFIG_SYNC_FILE_RANGE
520     if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) {
521         /*
522          * Initiate a writeback. This is not a data integrity sync.
523          * We want to ensure that we don't leave dirty pages in the cache
524          * after write when writeout=immediate is sepcified.
525          */
526         sync_file_range(fs->fd, offset, ret,
527                         SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE);
528     }
529 #endif
530     return ret;
531 }
532 
533 static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
534 {
535     char *dirpath = g_path_get_dirname(fs_path->data);
536     char *name = g_path_get_basename(fs_path->data);
537     int ret = -1;
538     int dirfd;
539 
540     dirfd = local_opendir_nofollow(fs_ctx, dirpath);
541     if (dirfd == -1) {
542         goto out;
543     }
544 
545     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
546         ret = local_set_xattrat(dirfd, name, credp);
547     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
548         ret = local_set_mapped_file_attrat(dirfd, name, credp);
549     } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
550                fs_ctx->export_flags & V9FS_SM_NONE) {
551         ret = fchmodat_nofollow(dirfd, name, credp->fc_mode);
552     }
553     close_preserve_errno(dirfd);
554 
555 out:
556     g_free(dirpath);
557     g_free(name);
558     return ret;
559 }
560 
561 static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
562                        const char *name, FsCred *credp)
563 {
564     int err = -1;
565     int dirfd;
566 
567     if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
568         local_is_mapped_file_metadata(fs_ctx, name)) {
569         errno = EINVAL;
570         return -1;
571     }
572 
573     dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
574     if (dirfd == -1) {
575         return -1;
576     }
577 
578     if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
579         fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
580         err = mknodat(dirfd, name, SM_LOCAL_MODE_BITS | S_IFREG, 0);
581         if (err == -1) {
582             goto out;
583         }
584 
585         if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
586             err = local_set_xattrat(dirfd, name, credp);
587         } else {
588             err = local_set_mapped_file_attrat(dirfd, name, credp);
589         }
590         if (err == -1) {
591             goto err_end;
592         }
593     } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
594                fs_ctx->export_flags & V9FS_SM_NONE) {
595         err = mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev);
596         if (err == -1) {
597             goto out;
598         }
599         err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
600         if (err == -1) {
601             goto err_end;
602         }
603     }
604     goto out;
605 
606 err_end:
607     unlinkat_preserve_errno(dirfd, name, 0);
608 out:
609     close_preserve_errno(dirfd);
610     return err;
611 }
612 
613 static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
614                        const char *name, FsCred *credp)
615 {
616     int err = -1;
617     int dirfd;
618 
619     if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
620         local_is_mapped_file_metadata(fs_ctx, name)) {
621         errno = EINVAL;
622         return -1;
623     }
624 
625     dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
626     if (dirfd == -1) {
627         return -1;
628     }
629 
630     if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
631         fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
632         err = mkdirat(dirfd, name, SM_LOCAL_DIR_MODE_BITS);
633         if (err == -1) {
634             goto out;
635         }
636         credp->fc_mode = credp->fc_mode | S_IFDIR;
637 
638         if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
639             err = local_set_xattrat(dirfd, name, credp);
640         } else {
641             err = local_set_mapped_file_attrat(dirfd, name, credp);
642         }
643         if (err == -1) {
644             goto err_end;
645         }
646     } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
647                fs_ctx->export_flags & V9FS_SM_NONE) {
648         err = mkdirat(dirfd, name, credp->fc_mode);
649         if (err == -1) {
650             goto out;
651         }
652         err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
653         if (err == -1) {
654             goto err_end;
655         }
656     }
657     goto out;
658 
659 err_end:
660     unlinkat_preserve_errno(dirfd, name, AT_REMOVEDIR);
661 out:
662     close_preserve_errno(dirfd);
663     return err;
664 }
665 
666 static int local_fstat(FsContext *fs_ctx, int fid_type,
667                        V9fsFidOpenState *fs, struct stat *stbuf)
668 {
669     int err, fd;
670 
671     if (fid_type == P9_FID_DIR) {
672         fd = dirfd(fs->dir.stream);
673     } else {
674         fd = fs->fd;
675     }
676 
677     err = fstat(fd, stbuf);
678     if (err) {
679         return err;
680     }
681     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
682         /* Actual credentials are part of extended attrs */
683         uid_t tmp_uid;
684         gid_t tmp_gid;
685         mode_t tmp_mode;
686         dev_t tmp_dev;
687 
688         if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) {
689             stbuf->st_uid = le32_to_cpu(tmp_uid);
690         }
691         if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) {
692             stbuf->st_gid = le32_to_cpu(tmp_gid);
693         }
694         if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) {
695             stbuf->st_mode = le32_to_cpu(tmp_mode);
696         }
697         if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) {
698             stbuf->st_rdev = le64_to_cpu(tmp_dev);
699         }
700     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
701         errno = EOPNOTSUPP;
702         return -1;
703     }
704     return err;
705 }
706 
707 static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
708                        int flags, FsCred *credp, V9fsFidOpenState *fs)
709 {
710     int fd = -1;
711     int err = -1;
712     int dirfd;
713 
714     if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
715         local_is_mapped_file_metadata(fs_ctx, name)) {
716         errno = EINVAL;
717         return -1;
718     }
719 
720     /*
721      * Mark all the open to not follow symlinks
722      */
723     flags |= O_NOFOLLOW;
724 
725     dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
726     if (dirfd == -1) {
727         return -1;
728     }
729 
730     /* Determine the security model */
731     if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
732         fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
733         fd = openat_file(dirfd, name, flags, SM_LOCAL_MODE_BITS);
734         if (fd == -1) {
735             goto out;
736         }
737         credp->fc_mode = credp->fc_mode|S_IFREG;
738         if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
739             /* Set cleint credentials in xattr */
740             err = local_set_xattrat(dirfd, name, credp);
741         } else {
742             err = local_set_mapped_file_attrat(dirfd, name, credp);
743         }
744         if (err == -1) {
745             goto err_end;
746         }
747     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
748                (fs_ctx->export_flags & V9FS_SM_NONE)) {
749         fd = openat_file(dirfd, name, flags, credp->fc_mode);
750         if (fd == -1) {
751             goto out;
752         }
753         err = local_set_cred_passthrough(fs_ctx, dirfd, name, credp);
754         if (err == -1) {
755             goto err_end;
756         }
757     }
758     err = fd;
759     fs->fd = fd;
760     goto out;
761 
762 err_end:
763     unlinkat_preserve_errno(dirfd, name,
764                             flags & O_DIRECTORY ? AT_REMOVEDIR : 0);
765     close_preserve_errno(fd);
766 out:
767     close_preserve_errno(dirfd);
768     return err;
769 }
770 
771 
772 static int local_symlink(FsContext *fs_ctx, const char *oldpath,
773                          V9fsPath *dir_path, const char *name, FsCred *credp)
774 {
775     int err = -1;
776     int dirfd;
777 
778     if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE &&
779         local_is_mapped_file_metadata(fs_ctx, name)) {
780         errno = EINVAL;
781         return -1;
782     }
783 
784     dirfd = local_opendir_nofollow(fs_ctx, dir_path->data);
785     if (dirfd == -1) {
786         return -1;
787     }
788 
789     /* Determine the security model */
790     if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
791         fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
792         int fd;
793         ssize_t oldpath_size, write_size;
794 
795         fd = openat_file(dirfd, name, O_CREAT | O_EXCL | O_RDWR,
796                          SM_LOCAL_MODE_BITS);
797         if (fd == -1) {
798             goto out;
799         }
800         /* Write the oldpath (target) to the file. */
801         oldpath_size = strlen(oldpath);
802         do {
803             write_size = write(fd, (void *)oldpath, oldpath_size);
804         } while (write_size == -1 && errno == EINTR);
805         close_preserve_errno(fd);
806 
807         if (write_size != oldpath_size) {
808             goto err_end;
809         }
810         /* Set cleint credentials in symlink's xattr */
811         credp->fc_mode = credp->fc_mode | S_IFLNK;
812 
813         if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
814             err = local_set_xattrat(dirfd, name, credp);
815         } else {
816             err = local_set_mapped_file_attrat(dirfd, name, credp);
817         }
818         if (err == -1) {
819             goto err_end;
820         }
821     } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
822                fs_ctx->export_flags & V9FS_SM_NONE) {
823         err = symlinkat(oldpath, dirfd, name);
824         if (err) {
825             goto out;
826         }
827         err = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
828                        AT_SYMLINK_NOFOLLOW);
829         if (err == -1) {
830             /*
831              * If we fail to change ownership and if we are
832              * using security model none. Ignore the error
833              */
834             if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
835                 goto err_end;
836             } else {
837                 err = 0;
838             }
839         }
840     }
841     goto out;
842 
843 err_end:
844     unlinkat_preserve_errno(dirfd, name, 0);
845 out:
846     close_preserve_errno(dirfd);
847     return err;
848 }
849 
850 static int local_link(FsContext *ctx, V9fsPath *oldpath,
851                       V9fsPath *dirpath, const char *name)
852 {
853     char *odirpath = g_path_get_dirname(oldpath->data);
854     char *oname = g_path_get_basename(oldpath->data);
855     int ret = -1;
856     int odirfd, ndirfd;
857 
858     if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
859         local_is_mapped_file_metadata(ctx, name)) {
860         errno = EINVAL;
861         return -1;
862     }
863 
864     odirfd = local_opendir_nofollow(ctx, odirpath);
865     if (odirfd == -1) {
866         goto out;
867     }
868 
869     ndirfd = local_opendir_nofollow(ctx, dirpath->data);
870     if (ndirfd == -1) {
871         close_preserve_errno(odirfd);
872         goto out;
873     }
874 
875     ret = linkat(odirfd, oname, ndirfd, name, 0);
876     if (ret < 0) {
877         goto out_close;
878     }
879 
880     /* now link the virtfs_metadata files */
881     if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
882         int omap_dirfd, nmap_dirfd;
883 
884         ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700);
885         if (ret < 0 && errno != EEXIST) {
886             goto err_undo_link;
887         }
888 
889         omap_dirfd = openat_dir(odirfd, VIRTFS_META_DIR);
890         if (omap_dirfd == -1) {
891             goto err;
892         }
893 
894         nmap_dirfd = openat_dir(ndirfd, VIRTFS_META_DIR);
895         if (nmap_dirfd == -1) {
896             close_preserve_errno(omap_dirfd);
897             goto err;
898         }
899 
900         ret = linkat(omap_dirfd, oname, nmap_dirfd, name, 0);
901         close_preserve_errno(nmap_dirfd);
902         close_preserve_errno(omap_dirfd);
903         if (ret < 0 && errno != ENOENT) {
904             goto err_undo_link;
905         }
906 
907         ret = 0;
908     }
909     goto out_close;
910 
911 err:
912     ret = -1;
913 err_undo_link:
914     unlinkat_preserve_errno(ndirfd, name, 0);
915 out_close:
916     close_preserve_errno(ndirfd);
917     close_preserve_errno(odirfd);
918 out:
919     g_free(oname);
920     g_free(odirpath);
921     return ret;
922 }
923 
924 static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size)
925 {
926     int fd, ret;
927 
928     fd = local_open_nofollow(ctx, fs_path->data, O_WRONLY, 0);
929     if (fd == -1) {
930         return -1;
931     }
932     ret = ftruncate(fd, size);
933     close_preserve_errno(fd);
934     return ret;
935 }
936 
937 static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
938 {
939     char *dirpath = g_path_get_dirname(fs_path->data);
940     char *name = g_path_get_basename(fs_path->data);
941     int ret = -1;
942     int dirfd;
943 
944     dirfd = local_opendir_nofollow(fs_ctx, dirpath);
945     if (dirfd == -1) {
946         goto out;
947     }
948 
949     if ((credp->fc_uid == -1 && credp->fc_gid == -1) ||
950         (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
951         (fs_ctx->export_flags & V9FS_SM_NONE)) {
952         ret = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid,
953                        AT_SYMLINK_NOFOLLOW);
954     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
955         ret = local_set_xattrat(dirfd, name, credp);
956     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
957         ret = local_set_mapped_file_attrat(dirfd, name, credp);
958     }
959 
960     close_preserve_errno(dirfd);
961 out:
962     g_free(name);
963     g_free(dirpath);
964     return ret;
965 }
966 
967 static int local_utimensat(FsContext *s, V9fsPath *fs_path,
968                            const struct timespec *buf)
969 {
970     char *dirpath = g_path_get_dirname(fs_path->data);
971     char *name = g_path_get_basename(fs_path->data);
972     int dirfd, ret = -1;
973 
974     dirfd = local_opendir_nofollow(s, dirpath);
975     if (dirfd == -1) {
976         goto out;
977     }
978 
979     ret = utimensat(dirfd, name, buf, AT_SYMLINK_NOFOLLOW);
980     close_preserve_errno(dirfd);
981 out:
982     g_free(dirpath);
983     g_free(name);
984     return ret;
985 }
986 
987 static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
988                                  int flags)
989 {
990     int ret = -1;
991 
992     if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
993         int map_dirfd;
994 
995         if (flags == AT_REMOVEDIR) {
996             int fd;
997 
998             fd = openat_dir(dirfd, name);
999             if (fd == -1) {
1000                 goto err_out;
1001             }
1002             /*
1003              * If directory remove .virtfs_metadata contained in the
1004              * directory
1005              */
1006             ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
1007             close_preserve_errno(fd);
1008             if (ret < 0 && errno != ENOENT) {
1009                 /*
1010                  * We didn't had the .virtfs_metadata file. May be file created
1011                  * in non-mapped mode ?. Ignore ENOENT.
1012                  */
1013                 goto err_out;
1014             }
1015         }
1016         /*
1017          * Now remove the name from parent directory
1018          * .virtfs_metadata directory.
1019          */
1020         map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
1021         ret = unlinkat(map_dirfd, name, 0);
1022         close_preserve_errno(map_dirfd);
1023         if (ret < 0 && errno != ENOENT) {
1024             /*
1025              * We didn't had the .virtfs_metadata file. May be file created
1026              * in non-mapped mode ?. Ignore ENOENT.
1027              */
1028             goto err_out;
1029         }
1030     }
1031 
1032     ret = unlinkat(dirfd, name, flags);
1033 err_out:
1034     return ret;
1035 }
1036 
1037 static int local_remove(FsContext *ctx, const char *path)
1038 {
1039     struct stat stbuf;
1040     char *dirpath = g_path_get_dirname(path);
1041     char *name = g_path_get_basename(path);
1042     int flags = 0;
1043     int dirfd;
1044     int err = -1;
1045 
1046     dirfd = local_opendir_nofollow(ctx, dirpath);
1047     if (dirfd == -1) {
1048         goto out;
1049     }
1050 
1051     if (fstatat(dirfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0) {
1052         goto err_out;
1053     }
1054 
1055     if (S_ISDIR(stbuf.st_mode)) {
1056         flags |= AT_REMOVEDIR;
1057     }
1058 
1059     err = local_unlinkat_common(ctx, dirfd, name, flags);
1060 err_out:
1061     close_preserve_errno(dirfd);
1062 out:
1063     g_free(name);
1064     g_free(dirpath);
1065     return err;
1066 }
1067 
1068 static int local_fsync(FsContext *ctx, int fid_type,
1069                        V9fsFidOpenState *fs, int datasync)
1070 {
1071     int fd;
1072 
1073     if (fid_type == P9_FID_DIR) {
1074         fd = dirfd(fs->dir.stream);
1075     } else {
1076         fd = fs->fd;
1077     }
1078 
1079     if (datasync) {
1080         return qemu_fdatasync(fd);
1081     } else {
1082         return fsync(fd);
1083     }
1084 }
1085 
1086 static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
1087 {
1088     int fd, ret;
1089 
1090     fd = local_open_nofollow(s, fs_path->data, O_RDONLY, 0);
1091     if (fd == -1) {
1092         return -1;
1093     }
1094     ret = fstatfs(fd, stbuf);
1095     close_preserve_errno(fd);
1096     return ret;
1097 }
1098 
1099 static ssize_t local_lgetxattr(FsContext *ctx, V9fsPath *fs_path,
1100                                const char *name, void *value, size_t size)
1101 {
1102     char *path = fs_path->data;
1103 
1104     return v9fs_get_xattr(ctx, path, name, value, size);
1105 }
1106 
1107 static ssize_t local_llistxattr(FsContext *ctx, V9fsPath *fs_path,
1108                                 void *value, size_t size)
1109 {
1110     char *path = fs_path->data;
1111 
1112     return v9fs_list_xattr(ctx, path, value, size);
1113 }
1114 
1115 static int local_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name,
1116                            void *value, size_t size, int flags)
1117 {
1118     char *path = fs_path->data;
1119 
1120     return v9fs_set_xattr(ctx, path, name, value, size, flags);
1121 }
1122 
1123 static int local_lremovexattr(FsContext *ctx, V9fsPath *fs_path,
1124                               const char *name)
1125 {
1126     char *path = fs_path->data;
1127 
1128     return v9fs_remove_xattr(ctx, path, name);
1129 }
1130 
1131 static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path,
1132                               const char *name, V9fsPath *target)
1133 {
1134     if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
1135         local_is_mapped_file_metadata(ctx, name)) {
1136         errno = EINVAL;
1137         return -1;
1138     }
1139 
1140     if (dir_path) {
1141         v9fs_path_sprintf(target, "%s/%s", dir_path->data, name);
1142     } else if (strcmp(name, "/")) {
1143         v9fs_path_sprintf(target, "%s", name);
1144     } else {
1145         /* We want the path of the export root to be relative, otherwise
1146          * "*at()" syscalls would treat it as "/" in the host.
1147          */
1148         v9fs_path_sprintf(target, "%s", ".");
1149     }
1150     return 0;
1151 }
1152 
1153 static int local_renameat(FsContext *ctx, V9fsPath *olddir,
1154                           const char *old_name, V9fsPath *newdir,
1155                           const char *new_name)
1156 {
1157     int ret;
1158     int odirfd, ndirfd;
1159 
1160     if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
1161         (local_is_mapped_file_metadata(ctx, old_name) ||
1162          local_is_mapped_file_metadata(ctx, new_name))) {
1163         errno = EINVAL;
1164         return -1;
1165     }
1166 
1167     odirfd = local_opendir_nofollow(ctx, olddir->data);
1168     if (odirfd == -1) {
1169         return -1;
1170     }
1171 
1172     ndirfd = local_opendir_nofollow(ctx, newdir->data);
1173     if (ndirfd == -1) {
1174         close_preserve_errno(odirfd);
1175         return -1;
1176     }
1177 
1178     ret = renameat(odirfd, old_name, ndirfd, new_name);
1179     if (ret < 0) {
1180         goto out;
1181     }
1182 
1183     if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1184         int omap_dirfd, nmap_dirfd;
1185 
1186         ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700);
1187         if (ret < 0 && errno != EEXIST) {
1188             goto err_undo_rename;
1189         }
1190 
1191         omap_dirfd = openat_dir(odirfd, VIRTFS_META_DIR);
1192         if (omap_dirfd == -1) {
1193             goto err;
1194         }
1195 
1196         nmap_dirfd = openat_dir(ndirfd, VIRTFS_META_DIR);
1197         if (nmap_dirfd == -1) {
1198             close_preserve_errno(omap_dirfd);
1199             goto err;
1200         }
1201 
1202         /* rename the .virtfs_metadata files */
1203         ret = renameat(omap_dirfd, old_name, nmap_dirfd, new_name);
1204         close_preserve_errno(nmap_dirfd);
1205         close_preserve_errno(omap_dirfd);
1206         if (ret < 0 && errno != ENOENT) {
1207             goto err_undo_rename;
1208         }
1209 
1210         ret = 0;
1211     }
1212     goto out;
1213 
1214 err:
1215     ret = -1;
1216 err_undo_rename:
1217     renameat_preserve_errno(ndirfd, new_name, odirfd, old_name);
1218 out:
1219     close_preserve_errno(ndirfd);
1220     close_preserve_errno(odirfd);
1221     return ret;
1222 }
1223 
1224 static void v9fs_path_init_dirname(V9fsPath *path, const char *str)
1225 {
1226     path->data = g_path_get_dirname(str);
1227     path->size = strlen(path->data) + 1;
1228 }
1229 
1230 static int local_rename(FsContext *ctx, const char *oldpath,
1231                         const char *newpath)
1232 {
1233     int err;
1234     char *oname = g_path_get_basename(oldpath);
1235     char *nname = g_path_get_basename(newpath);
1236     V9fsPath olddir, newdir;
1237 
1238     v9fs_path_init_dirname(&olddir, oldpath);
1239     v9fs_path_init_dirname(&newdir, newpath);
1240 
1241     err = local_renameat(ctx, &olddir, oname, &newdir, nname);
1242 
1243     v9fs_path_free(&newdir);
1244     v9fs_path_free(&olddir);
1245     g_free(nname);
1246     g_free(oname);
1247 
1248     return err;
1249 }
1250 
1251 static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
1252                           const char *name, int flags)
1253 {
1254     int ret;
1255     int dirfd;
1256 
1257     if (ctx->export_flags & V9FS_SM_MAPPED_FILE &&
1258         local_is_mapped_file_metadata(ctx, name)) {
1259         errno = EINVAL;
1260         return -1;
1261     }
1262 
1263     dirfd = local_opendir_nofollow(ctx, dir->data);
1264     if (dirfd == -1) {
1265         return -1;
1266     }
1267 
1268     ret = local_unlinkat_common(ctx, dirfd, name, flags);
1269     close_preserve_errno(dirfd);
1270     return ret;
1271 }
1272 
1273 static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
1274                                 mode_t st_mode, uint64_t *st_gen)
1275 {
1276 #ifdef FS_IOC_GETVERSION
1277     int err;
1278     V9fsFidOpenState fid_open;
1279 
1280     /*
1281      * Do not try to open special files like device nodes, fifos etc
1282      * We can get fd for regular files and directories only
1283      */
1284     if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
1285         errno = ENOTTY;
1286         return -1;
1287     }
1288     err = local_open(ctx, path, O_RDONLY, &fid_open);
1289     if (err < 0) {
1290         return err;
1291     }
1292     err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
1293     local_close(ctx, &fid_open);
1294     return err;
1295 #else
1296     errno = ENOTTY;
1297     return -1;
1298 #endif
1299 }
1300 
1301 static int local_init(FsContext *ctx)
1302 {
1303     struct statfs stbuf;
1304     LocalData *data = g_malloc(sizeof(*data));
1305 
1306     data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY);
1307     if (data->mountfd == -1) {
1308         goto err;
1309     }
1310 
1311 #ifdef FS_IOC_GETVERSION
1312     /*
1313      * use ioc_getversion only if the ioctl is definied
1314      */
1315     if (fstatfs(data->mountfd, &stbuf) < 0) {
1316         close_preserve_errno(data->mountfd);
1317         goto err;
1318     }
1319     switch (stbuf.f_type) {
1320     case EXT2_SUPER_MAGIC:
1321     case BTRFS_SUPER_MAGIC:
1322     case REISERFS_SUPER_MAGIC:
1323     case XFS_SUPER_MAGIC:
1324         ctx->exops.get_st_gen = local_ioc_getversion;
1325         break;
1326     }
1327 #endif
1328 
1329     if (ctx->export_flags & V9FS_SM_PASSTHROUGH) {
1330         ctx->xops = passthrough_xattr_ops;
1331     } else if (ctx->export_flags & V9FS_SM_MAPPED) {
1332         ctx->xops = mapped_xattr_ops;
1333     } else if (ctx->export_flags & V9FS_SM_NONE) {
1334         ctx->xops = none_xattr_ops;
1335     } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1336         /*
1337          * xattr operation for mapped-file and passthrough
1338          * remain same.
1339          */
1340         ctx->xops = passthrough_xattr_ops;
1341     }
1342     ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT;
1343 
1344     ctx->private = data;
1345     return 0;
1346 
1347 err:
1348     g_free(data);
1349     return -1;
1350 }
1351 
1352 static void local_cleanup(FsContext *ctx)
1353 {
1354     LocalData *data = ctx->private;
1355 
1356     close(data->mountfd);
1357     g_free(data);
1358 }
1359 
1360 static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
1361 {
1362     const char *sec_model = qemu_opt_get(opts, "security_model");
1363     const char *path = qemu_opt_get(opts, "path");
1364     Error *err = NULL;
1365 
1366     if (!sec_model) {
1367         error_report("Security model not specified, local fs needs security model");
1368         error_printf("valid options are:"
1369                      "\tsecurity_model=[passthrough|mapped-xattr|mapped-file|none]\n");
1370         return -1;
1371     }
1372 
1373     if (!strcmp(sec_model, "passthrough")) {
1374         fse->export_flags |= V9FS_SM_PASSTHROUGH;
1375     } else if (!strcmp(sec_model, "mapped") ||
1376                !strcmp(sec_model, "mapped-xattr")) {
1377         fse->export_flags |= V9FS_SM_MAPPED;
1378     } else if (!strcmp(sec_model, "none")) {
1379         fse->export_flags |= V9FS_SM_NONE;
1380     } else if (!strcmp(sec_model, "mapped-file")) {
1381         fse->export_flags |= V9FS_SM_MAPPED_FILE;
1382     } else {
1383         error_report("Invalid security model %s specified", sec_model);
1384         error_printf("valid options are:"
1385                      "\t[passthrough|mapped-xattr|mapped-file|none]\n");
1386         return -1;
1387     }
1388 
1389     if (!path) {
1390         error_report("fsdev: No path specified");
1391         return -1;
1392     }
1393 
1394     fsdev_throttle_parse_opts(opts, &fse->fst, &err);
1395     if (err) {
1396         error_reportf_err(err, "Throttle configuration is not valid: ");
1397         return -1;
1398     }
1399 
1400     fse->path = g_strdup(path);
1401 
1402     return 0;
1403 }
1404 
1405 FileOperations local_ops = {
1406     .parse_opts = local_parse_opts,
1407     .init  = local_init,
1408     .cleanup = local_cleanup,
1409     .lstat = local_lstat,
1410     .readlink = local_readlink,
1411     .close = local_close,
1412     .closedir = local_closedir,
1413     .open = local_open,
1414     .opendir = local_opendir,
1415     .rewinddir = local_rewinddir,
1416     .telldir = local_telldir,
1417     .readdir = local_readdir,
1418     .seekdir = local_seekdir,
1419     .preadv = local_preadv,
1420     .pwritev = local_pwritev,
1421     .chmod = local_chmod,
1422     .mknod = local_mknod,
1423     .mkdir = local_mkdir,
1424     .fstat = local_fstat,
1425     .open2 = local_open2,
1426     .symlink = local_symlink,
1427     .link = local_link,
1428     .truncate = local_truncate,
1429     .rename = local_rename,
1430     .chown = local_chown,
1431     .utimensat = local_utimensat,
1432     .remove = local_remove,
1433     .fsync = local_fsync,
1434     .statfs = local_statfs,
1435     .lgetxattr = local_lgetxattr,
1436     .llistxattr = local_llistxattr,
1437     .lsetxattr = local_lsetxattr,
1438     .lremovexattr = local_lremovexattr,
1439     .name_to_path = local_name_to_path,
1440     .renameat  = local_renameat,
1441     .unlinkat = local_unlinkat,
1442 };
1443