xref: /openbmc/qemu/hw/9pfs/cofs.c (revision 6f569084)
186e42d74SVenkateswararao Jujjuri (JV) /*
2af8b38b0SGreg Kurz  * 9p backend
386e42d74SVenkateswararao Jujjuri (JV)  *
486e42d74SVenkateswararao Jujjuri (JV)  * Copyright IBM, Corp. 2011
586e42d74SVenkateswararao Jujjuri (JV)  *
686e42d74SVenkateswararao Jujjuri (JV)  * Authors:
786e42d74SVenkateswararao Jujjuri (JV)  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
886e42d74SVenkateswararao Jujjuri (JV)  *
986e42d74SVenkateswararao Jujjuri (JV)  * This work is licensed under the terms of the GNU GPL, version 2.  See
1086e42d74SVenkateswararao Jujjuri (JV)  * the COPYING file in the top-level directory.
1186e42d74SVenkateswararao Jujjuri (JV)  *
1286e42d74SVenkateswararao Jujjuri (JV)  */
1386e42d74SVenkateswararao Jujjuri (JV) 
14*6f569084SChristian Schoenebeck /*
15*6f569084SChristian Schoenebeck  * Not so fast! You might want to read the 9p developer docs first:
16*6f569084SChristian Schoenebeck  * https://wiki.qemu.org/Documentation/9p
17*6f569084SChristian Schoenebeck  */
18*6f569084SChristian Schoenebeck 
19fbc04127SPeter Maydell #include "qemu/osdep.h"
2086e42d74SVenkateswararao Jujjuri (JV) #include "fsdev/qemu-fsdev.h"
211de7afc9SPaolo Bonzini #include "qemu/thread.h"
2210817bf0SDaniel P. Berrange #include "qemu/coroutine.h"
23db725815SMarkus Armbruster #include "qemu/main-loop.h"
24fe52840cSWei Liu #include "coth.h"
2586e42d74SVenkateswararao Jujjuri (JV) 
264fa4ce71SChen Gang static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
274fa4ce71SChen Gang {
284fa4ce71SChen Gang     ssize_t len, maxlen = PATH_MAX;
294fa4ce71SChen Gang 
304fa4ce71SChen Gang     buf->data = g_malloc(PATH_MAX);
314fa4ce71SChen Gang     for (;;) {
324fa4ce71SChen Gang         len = s->ops->readlink(&s->ctx, path, buf->data, maxlen);
334fa4ce71SChen Gang         if (len < 0) {
344fa4ce71SChen Gang             g_free(buf->data);
354fa4ce71SChen Gang             buf->data = NULL;
364fa4ce71SChen Gang             buf->size = 0;
374fa4ce71SChen Gang             break;
384fa4ce71SChen Gang         } else if (len == maxlen) {
394fa4ce71SChen Gang             /*
404fa4ce71SChen Gang              * We dodn't have space to put the NULL or we have more
414fa4ce71SChen Gang              * to read. Increase the size and try again
424fa4ce71SChen Gang              */
434fa4ce71SChen Gang             maxlen *= 2;
444fa4ce71SChen Gang             g_free(buf->data);
454fa4ce71SChen Gang             buf->data = g_malloc(maxlen);
464fa4ce71SChen Gang             continue;
474fa4ce71SChen Gang         }
484fa4ce71SChen Gang         /*
494fa4ce71SChen Gang          * Null terminate the readlink output
504fa4ce71SChen Gang          */
514fa4ce71SChen Gang         buf->data[len] = '\0';
524fa4ce71SChen Gang         buf->size = len;
534fa4ce71SChen Gang         break;
544fa4ce71SChen Gang     }
554fa4ce71SChen Gang     return len;
564fa4ce71SChen Gang }
574fa4ce71SChen Gang 
585bdade66SGreg Kurz int coroutine_fn v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf)
5986e42d74SVenkateswararao Jujjuri (JV) {
6086e42d74SVenkateswararao Jujjuri (JV)     int err;
61bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
6286e42d74SVenkateswararao Jujjuri (JV) 
63bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
64bccacf6cSAneesh Kumar K.V         return -EINTR;
65bccacf6cSAneesh Kumar K.V     }
66532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
6786e42d74SVenkateswararao Jujjuri (JV)     v9fs_co_run_in_worker(
6886e42d74SVenkateswararao Jujjuri (JV)         {
694fa4ce71SChen Gang             err = __readlink(s, path, buf);
704fa4ce71SChen Gang             if (err < 0) {
7186e42d74SVenkateswararao Jujjuri (JV)                 err = -errno;
7286e42d74SVenkateswararao Jujjuri (JV)             }
7386e42d74SVenkateswararao Jujjuri (JV)         });
74532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
7586e42d74SVenkateswararao Jujjuri (JV)     return err;
7686e42d74SVenkateswararao Jujjuri (JV) }
7794840ff9SAneesh Kumar K.V 
785bdade66SGreg Kurz int coroutine_fn v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path,
795bdade66SGreg Kurz                                 struct statfs *stbuf)
8094840ff9SAneesh Kumar K.V {
8194840ff9SAneesh Kumar K.V     int err;
82bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
8394840ff9SAneesh Kumar K.V 
84bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
85bccacf6cSAneesh Kumar K.V         return -EINTR;
86bccacf6cSAneesh Kumar K.V     }
87532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
8894840ff9SAneesh Kumar K.V     v9fs_co_run_in_worker(
8994840ff9SAneesh Kumar K.V         {
902289be19SAneesh Kumar K.V             err = s->ops->statfs(&s->ctx, path, stbuf);
9194840ff9SAneesh Kumar K.V             if (err < 0) {
9294840ff9SAneesh Kumar K.V                 err = -errno;
9394840ff9SAneesh Kumar K.V             }
9494840ff9SAneesh Kumar K.V         });
95532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
9694840ff9SAneesh Kumar K.V     return err;
9794840ff9SAneesh Kumar K.V }
984011ead2SAneesh Kumar K.V 
995bdade66SGreg Kurz int coroutine_fn v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode)
1004011ead2SAneesh Kumar K.V {
1014011ead2SAneesh Kumar K.V     int err;
1024011ead2SAneesh Kumar K.V     FsCred cred;
103bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1044011ead2SAneesh Kumar K.V 
105bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
106bccacf6cSAneesh Kumar K.V         return -EINTR;
107bccacf6cSAneesh Kumar K.V     }
1084011ead2SAneesh Kumar K.V     cred_init(&cred);
1094011ead2SAneesh Kumar K.V     cred.fc_mode = mode;
110532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1114011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1124011ead2SAneesh Kumar K.V         {
1132289be19SAneesh Kumar K.V             err = s->ops->chmod(&s->ctx, path, &cred);
1144011ead2SAneesh Kumar K.V             if (err < 0) {
1154011ead2SAneesh Kumar K.V                 err = -errno;
1164011ead2SAneesh Kumar K.V             }
1174011ead2SAneesh Kumar K.V         });
118532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1194011ead2SAneesh Kumar K.V     return err;
1204011ead2SAneesh Kumar K.V }
1214011ead2SAneesh Kumar K.V 
1225bdade66SGreg Kurz int coroutine_fn v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path,
1234011ead2SAneesh Kumar K.V                                    struct timespec times[2])
1244011ead2SAneesh Kumar K.V {
1254011ead2SAneesh Kumar K.V     int err;
126bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1274011ead2SAneesh Kumar K.V 
128bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
129bccacf6cSAneesh Kumar K.V         return -EINTR;
130bccacf6cSAneesh Kumar K.V     }
131532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1324011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1334011ead2SAneesh Kumar K.V         {
1342289be19SAneesh Kumar K.V             err = s->ops->utimensat(&s->ctx, path, times);
1354011ead2SAneesh Kumar K.V             if (err < 0) {
1364011ead2SAneesh Kumar K.V                 err = -errno;
1374011ead2SAneesh Kumar K.V             }
1384011ead2SAneesh Kumar K.V         });
139532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1404011ead2SAneesh Kumar K.V     return err;
1414011ead2SAneesh Kumar K.V }
1424011ead2SAneesh Kumar K.V 
1435bdade66SGreg Kurz int coroutine_fn v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid,
1445bdade66SGreg Kurz                                gid_t gid)
1454011ead2SAneesh Kumar K.V {
1464011ead2SAneesh Kumar K.V     int err;
1474011ead2SAneesh Kumar K.V     FsCred cred;
148bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1494011ead2SAneesh Kumar K.V 
150bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
151bccacf6cSAneesh Kumar K.V         return -EINTR;
152bccacf6cSAneesh Kumar K.V     }
1534011ead2SAneesh Kumar K.V     cred_init(&cred);
1544011ead2SAneesh Kumar K.V     cred.fc_uid = uid;
1554011ead2SAneesh Kumar K.V     cred.fc_gid = gid;
156532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1574011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1584011ead2SAneesh Kumar K.V         {
1592289be19SAneesh Kumar K.V             err = s->ops->chown(&s->ctx, path, &cred);
1604011ead2SAneesh Kumar K.V             if (err < 0) {
1614011ead2SAneesh Kumar K.V                 err = -errno;
1624011ead2SAneesh Kumar K.V             }
1634011ead2SAneesh Kumar K.V         });
164532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1654011ead2SAneesh Kumar K.V     return err;
1664011ead2SAneesh Kumar K.V }
1674011ead2SAneesh Kumar K.V 
1685bdade66SGreg Kurz int coroutine_fn v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size)
1694011ead2SAneesh Kumar K.V {
1704011ead2SAneesh Kumar K.V     int err;
171bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1724011ead2SAneesh Kumar K.V 
173bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
174bccacf6cSAneesh Kumar K.V         return -EINTR;
175bccacf6cSAneesh Kumar K.V     }
176532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1774011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1784011ead2SAneesh Kumar K.V         {
1792289be19SAneesh Kumar K.V             err = s->ops->truncate(&s->ctx, path, size);
1804011ead2SAneesh Kumar K.V             if (err < 0) {
1814011ead2SAneesh Kumar K.V                 err = -errno;
1824011ead2SAneesh Kumar K.V             }
1834011ead2SAneesh Kumar K.V         });
184532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1854011ead2SAneesh Kumar K.V     return err;
1864011ead2SAneesh Kumar K.V }
18700ace8c5SAneesh Kumar K.V 
1885bdade66SGreg Kurz int coroutine_fn v9fs_co_mknod(V9fsPDU *pdu, V9fsFidState *fidp,
1895bdade66SGreg Kurz                                V9fsString *name, uid_t uid, gid_t gid,
1905bdade66SGreg Kurz                                dev_t dev, mode_t mode, struct stat *stbuf)
19100ace8c5SAneesh Kumar K.V {
19200ace8c5SAneesh Kumar K.V     int err;
1932289be19SAneesh Kumar K.V     V9fsPath path;
19400ace8c5SAneesh Kumar K.V     FsCred cred;
195bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
19600ace8c5SAneesh Kumar K.V 
197bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
198bccacf6cSAneesh Kumar K.V         return -EINTR;
199bccacf6cSAneesh Kumar K.V     }
20000ace8c5SAneesh Kumar K.V     cred_init(&cred);
20100ace8c5SAneesh Kumar K.V     cred.fc_uid  = uid;
20200ace8c5SAneesh Kumar K.V     cred.fc_gid  = gid;
20300ace8c5SAneesh Kumar K.V     cred.fc_mode = mode;
20400ace8c5SAneesh Kumar K.V     cred.fc_rdev = dev;
205532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
20600ace8c5SAneesh Kumar K.V     v9fs_co_run_in_worker(
20700ace8c5SAneesh Kumar K.V         {
2082289be19SAneesh Kumar K.V             err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred);
20902cb7f3aSAneesh Kumar K.V             if (err < 0) {
21002cb7f3aSAneesh Kumar K.V                 err = -errno;
21102cb7f3aSAneesh Kumar K.V             } else {
2122289be19SAneesh Kumar K.V                 v9fs_path_init(&path);
2132289be19SAneesh Kumar K.V                 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
2142289be19SAneesh Kumar K.V                 if (!err) {
2152289be19SAneesh Kumar K.V                     err = s->ops->lstat(&s->ctx, &path, stbuf);
21600ace8c5SAneesh Kumar K.V                     if (err < 0) {
21700ace8c5SAneesh Kumar K.V                         err = -errno;
21800ace8c5SAneesh Kumar K.V                     }
21902cb7f3aSAneesh Kumar K.V                 }
2202289be19SAneesh Kumar K.V                 v9fs_path_free(&path);
2212289be19SAneesh Kumar K.V             }
22200ace8c5SAneesh Kumar K.V         });
223532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
22400ace8c5SAneesh Kumar K.V     return err;
22500ace8c5SAneesh Kumar K.V }
226b4b1537bSVenkateswararao Jujjuri 
2272289be19SAneesh Kumar K.V /* Only works with path name based fid */
2285bdade66SGreg Kurz int coroutine_fn v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path)
229b4b1537bSVenkateswararao Jujjuri {
230b4b1537bSVenkateswararao Jujjuri     int err;
231bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
232b4b1537bSVenkateswararao Jujjuri 
233bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
234bccacf6cSAneesh Kumar K.V         return -EINTR;
235bccacf6cSAneesh Kumar K.V     }
236532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
237b4b1537bSVenkateswararao Jujjuri     v9fs_co_run_in_worker(
238b4b1537bSVenkateswararao Jujjuri         {
239b4b1537bSVenkateswararao Jujjuri             err = s->ops->remove(&s->ctx, path->data);
240b4b1537bSVenkateswararao Jujjuri             if (err < 0) {
241b4b1537bSVenkateswararao Jujjuri                 err = -errno;
242b4b1537bSVenkateswararao Jujjuri             }
243b4b1537bSVenkateswararao Jujjuri         });
244532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
245b4b1537bSVenkateswararao Jujjuri     return err;
246b4b1537bSVenkateswararao Jujjuri }
2472a487e05SAneesh Kumar K.V 
2485bdade66SGreg Kurz int coroutine_fn v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path,
2495bdade66SGreg Kurz                                   V9fsString *name, int flags)
2502289be19SAneesh Kumar K.V {
2512289be19SAneesh Kumar K.V     int err;
252bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
2532289be19SAneesh Kumar K.V 
254bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
255bccacf6cSAneesh Kumar K.V         return -EINTR;
256bccacf6cSAneesh Kumar K.V     }
257532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
2582289be19SAneesh Kumar K.V     v9fs_co_run_in_worker(
2592289be19SAneesh Kumar K.V         {
2602289be19SAneesh Kumar K.V             err = s->ops->unlinkat(&s->ctx, path, name->data, flags);
2612289be19SAneesh Kumar K.V             if (err < 0) {
2622289be19SAneesh Kumar K.V                 err = -errno;
2632289be19SAneesh Kumar K.V             }
2642289be19SAneesh Kumar K.V         });
265532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
2662289be19SAneesh Kumar K.V     return err;
2672289be19SAneesh Kumar K.V }
2682289be19SAneesh Kumar K.V 
2692289be19SAneesh Kumar K.V /* Only work with path name based fid */
2705bdade66SGreg Kurz int coroutine_fn v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath,
2715bdade66SGreg Kurz                                 V9fsPath *newpath)
2722a487e05SAneesh Kumar K.V {
2732a487e05SAneesh Kumar K.V     int err;
274bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
2752a487e05SAneesh Kumar K.V 
276bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
277bccacf6cSAneesh Kumar K.V         return -EINTR;
278bccacf6cSAneesh Kumar K.V     }
2792a487e05SAneesh Kumar K.V     v9fs_co_run_in_worker(
2802a487e05SAneesh Kumar K.V         {
2812a487e05SAneesh Kumar K.V             err = s->ops->rename(&s->ctx, oldpath->data, newpath->data);
2822a487e05SAneesh Kumar K.V             if (err < 0) {
2832a487e05SAneesh Kumar K.V                 err = -errno;
2842a487e05SAneesh Kumar K.V             }
2852a487e05SAneesh Kumar K.V         });
2862a487e05SAneesh Kumar K.V     return err;
2872a487e05SAneesh Kumar K.V }
28802ac7a34SVenkateswararao Jujjuri 
2895bdade66SGreg Kurz int coroutine_fn v9fs_co_renameat(V9fsPDU *pdu, V9fsPath *olddirpath,
2905bdade66SGreg Kurz                                   V9fsString *oldname, V9fsPath *newdirpath,
2915bdade66SGreg Kurz                                   V9fsString *newname)
2922289be19SAneesh Kumar K.V {
2932289be19SAneesh Kumar K.V     int err;
294bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
2952289be19SAneesh Kumar K.V 
296bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
297bccacf6cSAneesh Kumar K.V         return -EINTR;
298bccacf6cSAneesh Kumar K.V     }
2992289be19SAneesh Kumar K.V     v9fs_co_run_in_worker(
3002289be19SAneesh Kumar K.V         {
3012289be19SAneesh Kumar K.V             err = s->ops->renameat(&s->ctx, olddirpath, oldname->data,
3022289be19SAneesh Kumar K.V                                    newdirpath, newname->data);
3032289be19SAneesh Kumar K.V             if (err < 0) {
3042289be19SAneesh Kumar K.V                 err = -errno;
3052289be19SAneesh Kumar K.V             }
3062289be19SAneesh Kumar K.V         });
3072289be19SAneesh Kumar K.V     return err;
3082289be19SAneesh Kumar K.V }
3092289be19SAneesh Kumar K.V 
3105bdade66SGreg Kurz int coroutine_fn v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp,
3115bdade66SGreg Kurz                                  V9fsString *name, const char *oldpath,
3125bdade66SGreg Kurz                                  gid_t gid, struct stat *stbuf)
31302ac7a34SVenkateswararao Jujjuri {
31402ac7a34SVenkateswararao Jujjuri     int err;
31502ac7a34SVenkateswararao Jujjuri     FsCred cred;
3162289be19SAneesh Kumar K.V     V9fsPath path;
317bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
31802cb7f3aSAneesh Kumar K.V 
319bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
320bccacf6cSAneesh Kumar K.V         return -EINTR;
321bccacf6cSAneesh Kumar K.V     }
32202ac7a34SVenkateswararao Jujjuri     cred_init(&cred);
32302cb7f3aSAneesh Kumar K.V     cred.fc_uid = dfidp->uid;
32402ac7a34SVenkateswararao Jujjuri     cred.fc_gid = gid;
32502ac7a34SVenkateswararao Jujjuri     cred.fc_mode = 0777;
326532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
32702ac7a34SVenkateswararao Jujjuri     v9fs_co_run_in_worker(
32802ac7a34SVenkateswararao Jujjuri         {
3292289be19SAneesh Kumar K.V             err = s->ops->symlink(&s->ctx, oldpath, &dfidp->path,
3302289be19SAneesh Kumar K.V                                   name->data, &cred);
33102cb7f3aSAneesh Kumar K.V             if (err < 0) {
33202cb7f3aSAneesh Kumar K.V                 err = -errno;
33302cb7f3aSAneesh Kumar K.V             } else {
3342289be19SAneesh Kumar K.V                 v9fs_path_init(&path);
3352289be19SAneesh Kumar K.V                 err = v9fs_name_to_path(s, &dfidp->path, name->data, &path);
3362289be19SAneesh Kumar K.V                 if (!err) {
3372289be19SAneesh Kumar K.V                     err = s->ops->lstat(&s->ctx, &path, stbuf);
33802ac7a34SVenkateswararao Jujjuri                     if (err < 0) {
33902ac7a34SVenkateswararao Jujjuri                         err = -errno;
34002ac7a34SVenkateswararao Jujjuri                     }
34102cb7f3aSAneesh Kumar K.V                 }
3422289be19SAneesh Kumar K.V                 v9fs_path_free(&path);
3432289be19SAneesh Kumar K.V             }
34402ac7a34SVenkateswararao Jujjuri         });
345532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
3462289be19SAneesh Kumar K.V     return err;
3472289be19SAneesh Kumar K.V }
3482289be19SAneesh Kumar K.V 
3492289be19SAneesh Kumar K.V /*
3502289be19SAneesh Kumar K.V  * For path name based fid we don't block. So we can
3512289be19SAneesh Kumar K.V  * directly call the fs driver ops.
3522289be19SAneesh Kumar K.V  */
3535bdade66SGreg Kurz int coroutine_fn v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath,
3542289be19SAneesh Kumar K.V                                       const char *name, V9fsPath *path)
3552289be19SAneesh Kumar K.V {
3562289be19SAneesh Kumar K.V     int err;
357bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
358532decb7SAneesh Kumar K.V 
359c98f1d4aSAneesh Kumar K.V     if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
3602289be19SAneesh Kumar K.V         err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
3612289be19SAneesh Kumar K.V         if (err < 0) {
3622289be19SAneesh Kumar K.V             err = -errno;
3632289be19SAneesh Kumar K.V         }
364532decb7SAneesh Kumar K.V     } else {
365bccacf6cSAneesh Kumar K.V         if (v9fs_request_cancelled(pdu)) {
366bccacf6cSAneesh Kumar K.V             return -EINTR;
367bccacf6cSAneesh Kumar K.V         }
368532decb7SAneesh Kumar K.V         v9fs_co_run_in_worker(
369532decb7SAneesh Kumar K.V             {
370532decb7SAneesh Kumar K.V                 err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
371532decb7SAneesh Kumar K.V                 if (err < 0) {
372532decb7SAneesh Kumar K.V                     err = -errno;
373532decb7SAneesh Kumar K.V                 }
374532decb7SAneesh Kumar K.V             });
375532decb7SAneesh Kumar K.V     }
37602ac7a34SVenkateswararao Jujjuri     return err;
37702ac7a34SVenkateswararao Jujjuri }
378