1172198d4SAneesh Kumar K.V 2172198d4SAneesh Kumar K.V /* 3172198d4SAneesh Kumar K.V * Virtio 9p backend 4172198d4SAneesh Kumar K.V * 5172198d4SAneesh Kumar K.V * Copyright IBM, Corp. 2011 6172198d4SAneesh Kumar K.V * 7172198d4SAneesh Kumar K.V * Authors: 8172198d4SAneesh Kumar K.V * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 9172198d4SAneesh Kumar K.V * 10172198d4SAneesh Kumar K.V * This work is licensed under the terms of the GNU GPL, version 2. See 11172198d4SAneesh Kumar K.V * the COPYING file in the top-level directory. 12172198d4SAneesh Kumar K.V * 13172198d4SAneesh Kumar K.V */ 14172198d4SAneesh Kumar K.V 15172198d4SAneesh Kumar K.V #include "fsdev/qemu-fsdev.h" 16172198d4SAneesh Kumar K.V #include "qemu-thread.h" 17172198d4SAneesh Kumar K.V #include "qemu-coroutine.h" 18172198d4SAneesh Kumar K.V #include "virtio-9p-coth.h" 19172198d4SAneesh Kumar K.V 20172198d4SAneesh Kumar K.V int v9fs_co_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf) 21172198d4SAneesh Kumar K.V { 22172198d4SAneesh Kumar K.V int err; 23172198d4SAneesh Kumar K.V 24172198d4SAneesh Kumar K.V v9fs_co_run_in_worker( 25172198d4SAneesh Kumar K.V { 26172198d4SAneesh Kumar K.V err = s->ops->lstat(&s->ctx, path->data, stbuf); 27172198d4SAneesh Kumar K.V if (err < 0) { 28172198d4SAneesh Kumar K.V err = -errno; 29172198d4SAneesh Kumar K.V } 30172198d4SAneesh Kumar K.V }); 31172198d4SAneesh Kumar K.V return err; 32172198d4SAneesh Kumar K.V } 3303feb1e1SAneesh Kumar K.V 3403feb1e1SAneesh Kumar K.V int v9fs_co_fstat(V9fsState *s, int fd, struct stat *stbuf) 3503feb1e1SAneesh Kumar K.V { 3603feb1e1SAneesh Kumar K.V int err; 3703feb1e1SAneesh Kumar K.V 3803feb1e1SAneesh Kumar K.V v9fs_co_run_in_worker( 3903feb1e1SAneesh Kumar K.V { 4003feb1e1SAneesh Kumar K.V err = s->ops->fstat(&s->ctx, fd, stbuf); 4103feb1e1SAneesh Kumar K.V if (err < 0) { 4203feb1e1SAneesh Kumar K.V err = -errno; 4303feb1e1SAneesh Kumar K.V } 4403feb1e1SAneesh Kumar K.V }); 4503feb1e1SAneesh Kumar K.V return err; 4603feb1e1SAneesh Kumar K.V } 47f6b7f0abSAneesh Kumar K.V 48f6b7f0abSAneesh Kumar K.V int v9fs_co_open(V9fsState *s, V9fsFidState *fidp, int flags) 49f6b7f0abSAneesh Kumar K.V { 50f6b7f0abSAneesh Kumar K.V int err; 51f6b7f0abSAneesh Kumar K.V 52f6b7f0abSAneesh Kumar K.V v9fs_co_run_in_worker( 53f6b7f0abSAneesh Kumar K.V { 54f6b7f0abSAneesh Kumar K.V fidp->fs.fd = s->ops->open(&s->ctx, fidp->path.data, flags); 55f6b7f0abSAneesh Kumar K.V if (fidp->fs.fd == -1) { 56f6b7f0abSAneesh Kumar K.V err = -errno; 57f6b7f0abSAneesh Kumar K.V } else { 58f6b7f0abSAneesh Kumar K.V err = 0; 59f6b7f0abSAneesh Kumar K.V } 60f6b7f0abSAneesh Kumar K.V }); 61f6b7f0abSAneesh Kumar K.V return err; 62f6b7f0abSAneesh Kumar K.V } 63e4de4232SVenkateswararao Jujjuri 64e4de4232SVenkateswararao Jujjuri int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, char *fullname, gid_t gid, 65e4de4232SVenkateswararao Jujjuri int flags, int mode) 66e4de4232SVenkateswararao Jujjuri { 67e4de4232SVenkateswararao Jujjuri int err; 68e4de4232SVenkateswararao Jujjuri FsCred cred; 69e4de4232SVenkateswararao Jujjuri 70e4de4232SVenkateswararao Jujjuri cred_init(&cred); 71e4de4232SVenkateswararao Jujjuri cred.fc_mode = mode & 07777; 72e4de4232SVenkateswararao Jujjuri cred.fc_uid = fidp->uid; 73e4de4232SVenkateswararao Jujjuri cred.fc_gid = gid; 74e4de4232SVenkateswararao Jujjuri v9fs_co_run_in_worker( 75e4de4232SVenkateswararao Jujjuri { 76e4de4232SVenkateswararao Jujjuri fidp->fs.fd = s->ops->open2(&s->ctx, fullname, flags, &cred); 77e4de4232SVenkateswararao Jujjuri err = 0; 78e4de4232SVenkateswararao Jujjuri if (fidp->fs.fd == -1) { 79e4de4232SVenkateswararao Jujjuri err = -errno; 80e4de4232SVenkateswararao Jujjuri } 81e4de4232SVenkateswararao Jujjuri }); 82e4de4232SVenkateswararao Jujjuri return err; 83e4de4232SVenkateswararao Jujjuri } 84bed4352cSAneesh Kumar K.V 85bed4352cSAneesh Kumar K.V int v9fs_co_close(V9fsState *s, V9fsFidState *fidp) 86bed4352cSAneesh Kumar K.V { 87bed4352cSAneesh Kumar K.V int fd; 88bed4352cSAneesh Kumar K.V int err; 89bed4352cSAneesh Kumar K.V 90bed4352cSAneesh Kumar K.V fd = fidp->fs.fd; 91bed4352cSAneesh Kumar K.V v9fs_co_run_in_worker( 92bed4352cSAneesh Kumar K.V { 93bed4352cSAneesh Kumar K.V err = s->ops->close(&s->ctx, fd); 94bed4352cSAneesh Kumar K.V if (err < 0) { 95bed4352cSAneesh Kumar K.V err = -errno; 96bed4352cSAneesh Kumar K.V } 97bed4352cSAneesh Kumar K.V }); 98bed4352cSAneesh Kumar K.V return err; 99bed4352cSAneesh Kumar K.V } 1004743d1f5SAneesh Kumar K.V 1014743d1f5SAneesh Kumar K.V int v9fs_co_fsync(V9fsState *s, V9fsFidState *fidp, int datasync) 1024743d1f5SAneesh Kumar K.V { 1034743d1f5SAneesh Kumar K.V int fd; 1044743d1f5SAneesh Kumar K.V int err; 1054743d1f5SAneesh Kumar K.V 1064743d1f5SAneesh Kumar K.V fd = fidp->fs.fd; 1074743d1f5SAneesh Kumar K.V v9fs_co_run_in_worker( 1084743d1f5SAneesh Kumar K.V { 1094743d1f5SAneesh Kumar K.V err = s->ops->fsync(&s->ctx, fd, datasync); 1104743d1f5SAneesh Kumar K.V if (err < 0) { 1114743d1f5SAneesh Kumar K.V err = -errno; 1124743d1f5SAneesh Kumar K.V } 1134743d1f5SAneesh Kumar K.V }); 1144743d1f5SAneesh Kumar K.V return err; 1154743d1f5SAneesh Kumar K.V } 116c6c069b0SVenkateswararao Jujjuri 117c6c069b0SVenkateswararao Jujjuri int v9fs_co_link(V9fsState *s, V9fsString *oldpath, V9fsString *newpath) 118c6c069b0SVenkateswararao Jujjuri { 119c6c069b0SVenkateswararao Jujjuri int err; 120c6c069b0SVenkateswararao Jujjuri 121c6c069b0SVenkateswararao Jujjuri v9fs_co_run_in_worker( 122c6c069b0SVenkateswararao Jujjuri { 123c6c069b0SVenkateswararao Jujjuri err = s->ops->link(&s->ctx, oldpath->data, newpath->data); 124c6c069b0SVenkateswararao Jujjuri if (err < 0) { 125c6c069b0SVenkateswararao Jujjuri err = -errno; 126c6c069b0SVenkateswararao Jujjuri } 127c6c069b0SVenkateswararao Jujjuri }); 128c6c069b0SVenkateswararao Jujjuri return err; 129c6c069b0SVenkateswararao Jujjuri } 130f6b3c976SAneesh Kumar K.V 131f6b3c976SAneesh Kumar K.V int v9fs_co_pwritev(V9fsState *s, V9fsFidState *fidp, 132f6b3c976SAneesh Kumar K.V struct iovec *iov, int iovcnt, int64_t offset) 133f6b3c976SAneesh Kumar K.V { 134f6b3c976SAneesh Kumar K.V int fd; 135f6b3c976SAneesh Kumar K.V int err; 136f6b3c976SAneesh Kumar K.V 137f6b3c976SAneesh Kumar K.V fd = fidp->fs.fd; 138f6b3c976SAneesh Kumar K.V v9fs_co_run_in_worker( 139f6b3c976SAneesh Kumar K.V { 140f6b3c976SAneesh Kumar K.V err = s->ops->pwritev(&s->ctx, fd, iov, iovcnt, offset); 141f6b3c976SAneesh Kumar K.V if (err < 0) { 142f6b3c976SAneesh Kumar K.V err = -errno; 143f6b3c976SAneesh Kumar K.V } 144f6b3c976SAneesh Kumar K.V }); 145f6b3c976SAneesh Kumar K.V return err; 146f6b3c976SAneesh Kumar K.V } 147*7eafdcc9SAneesh Kumar K.V 148*7eafdcc9SAneesh Kumar K.V int v9fs_co_preadv(V9fsState *s, V9fsFidState *fidp, 149*7eafdcc9SAneesh Kumar K.V struct iovec *iov, int iovcnt, int64_t offset) 150*7eafdcc9SAneesh Kumar K.V { 151*7eafdcc9SAneesh Kumar K.V int fd; 152*7eafdcc9SAneesh Kumar K.V int err; 153*7eafdcc9SAneesh Kumar K.V 154*7eafdcc9SAneesh Kumar K.V fd = fidp->fs.fd; 155*7eafdcc9SAneesh Kumar K.V v9fs_co_run_in_worker( 156*7eafdcc9SAneesh Kumar K.V { 157*7eafdcc9SAneesh Kumar K.V err = s->ops->preadv(&s->ctx, fd, iov, iovcnt, offset); 158*7eafdcc9SAneesh Kumar K.V if (err < 0) { 159*7eafdcc9SAneesh Kumar K.V err = -errno; 160*7eafdcc9SAneesh Kumar K.V } 161*7eafdcc9SAneesh Kumar K.V }); 162*7eafdcc9SAneesh Kumar K.V return err; 163*7eafdcc9SAneesh Kumar K.V } 164