xref: /openbmc/qemu/hw/9pfs/cofs.c (revision 23792478)
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"
22db725815SMarkus Armbruster #include "qemu/main-loop.h"
23fe52840cSWei Liu #include "coth.h"
2486e42d74SVenkateswararao Jujjuri (JV) 
__readlink(V9fsState * s,V9fsPath * path,V9fsString * buf)254fa4ce71SChen Gang static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
264fa4ce71SChen Gang {
274fa4ce71SChen Gang     ssize_t len, maxlen = PATH_MAX;
284fa4ce71SChen Gang 
294fa4ce71SChen Gang     buf->data = g_malloc(PATH_MAX);
304fa4ce71SChen Gang     for (;;) {
314fa4ce71SChen Gang         len = s->ops->readlink(&s->ctx, path, buf->data, maxlen);
324fa4ce71SChen Gang         if (len < 0) {
334fa4ce71SChen Gang             g_free(buf->data);
344fa4ce71SChen Gang             buf->data = NULL;
354fa4ce71SChen Gang             buf->size = 0;
364fa4ce71SChen Gang             break;
374fa4ce71SChen Gang         } else if (len == maxlen) {
384fa4ce71SChen Gang             /*
394fa4ce71SChen Gang              * We dodn't have space to put the NULL or we have more
404fa4ce71SChen Gang              * to read. Increase the size and try again
414fa4ce71SChen Gang              */
424fa4ce71SChen Gang             maxlen *= 2;
434fa4ce71SChen Gang             g_free(buf->data);
444fa4ce71SChen Gang             buf->data = g_malloc(maxlen);
454fa4ce71SChen Gang             continue;
464fa4ce71SChen Gang         }
474fa4ce71SChen Gang         /*
484fa4ce71SChen Gang          * Null terminate the readlink output
494fa4ce71SChen Gang          */
504fa4ce71SChen Gang         buf->data[len] = '\0';
514fa4ce71SChen Gang         buf->size = len;
524fa4ce71SChen Gang         break;
534fa4ce71SChen Gang     }
544fa4ce71SChen Gang     return len;
554fa4ce71SChen Gang }
564fa4ce71SChen Gang 
v9fs_co_readlink(V9fsPDU * pdu,V9fsPath * path,V9fsString * buf)575bdade66SGreg Kurz int coroutine_fn v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf)
5886e42d74SVenkateswararao Jujjuri (JV) {
5986e42d74SVenkateswararao Jujjuri (JV)     int err;
60bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
6186e42d74SVenkateswararao Jujjuri (JV) 
62bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
63bccacf6cSAneesh Kumar K.V         return -EINTR;
64bccacf6cSAneesh Kumar K.V     }
65532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
6686e42d74SVenkateswararao Jujjuri (JV)     v9fs_co_run_in_worker(
6786e42d74SVenkateswararao Jujjuri (JV)         {
684fa4ce71SChen Gang             err = __readlink(s, path, buf);
694fa4ce71SChen Gang             if (err < 0) {
7086e42d74SVenkateswararao Jujjuri (JV)                 err = -errno;
7186e42d74SVenkateswararao Jujjuri (JV)             }
7286e42d74SVenkateswararao Jujjuri (JV)         });
73532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
7486e42d74SVenkateswararao Jujjuri (JV)     return err;
7586e42d74SVenkateswararao Jujjuri (JV) }
7694840ff9SAneesh Kumar K.V 
v9fs_co_statfs(V9fsPDU * pdu,V9fsPath * path,struct statfs * stbuf)775bdade66SGreg Kurz int coroutine_fn v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path,
785bdade66SGreg Kurz                                 struct statfs *stbuf)
7994840ff9SAneesh Kumar K.V {
8094840ff9SAneesh Kumar K.V     int err;
81bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
8294840ff9SAneesh Kumar K.V 
83bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
84bccacf6cSAneesh Kumar K.V         return -EINTR;
85bccacf6cSAneesh Kumar K.V     }
86532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
8794840ff9SAneesh Kumar K.V     v9fs_co_run_in_worker(
8894840ff9SAneesh Kumar K.V         {
892289be19SAneesh Kumar K.V             err = s->ops->statfs(&s->ctx, path, stbuf);
9094840ff9SAneesh Kumar K.V             if (err < 0) {
9194840ff9SAneesh Kumar K.V                 err = -errno;
9294840ff9SAneesh Kumar K.V             }
9394840ff9SAneesh Kumar K.V         });
94532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
9594840ff9SAneesh Kumar K.V     return err;
9694840ff9SAneesh Kumar K.V }
974011ead2SAneesh Kumar K.V 
v9fs_co_chmod(V9fsPDU * pdu,V9fsPath * path,mode_t mode)985bdade66SGreg Kurz int coroutine_fn v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode)
994011ead2SAneesh Kumar K.V {
1004011ead2SAneesh Kumar K.V     int err;
1014011ead2SAneesh Kumar K.V     FsCred cred;
102bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1034011ead2SAneesh Kumar K.V 
104bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
105bccacf6cSAneesh Kumar K.V         return -EINTR;
106bccacf6cSAneesh Kumar K.V     }
1074011ead2SAneesh Kumar K.V     cred_init(&cred);
1084011ead2SAneesh Kumar K.V     cred.fc_mode = mode;
109532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1104011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1114011ead2SAneesh Kumar K.V         {
1122289be19SAneesh Kumar K.V             err = s->ops->chmod(&s->ctx, path, &cred);
1134011ead2SAneesh Kumar K.V             if (err < 0) {
1144011ead2SAneesh Kumar K.V                 err = -errno;
1154011ead2SAneesh Kumar K.V             }
1164011ead2SAneesh Kumar K.V         });
117532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1184011ead2SAneesh Kumar K.V     return err;
1194011ead2SAneesh Kumar K.V }
1204011ead2SAneesh Kumar K.V 
v9fs_co_utimensat(V9fsPDU * pdu,V9fsPath * path,struct timespec times[2])1215bdade66SGreg Kurz int coroutine_fn v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path,
1224011ead2SAneesh Kumar K.V                                    struct timespec times[2])
1234011ead2SAneesh Kumar K.V {
1244011ead2SAneesh Kumar K.V     int err;
125bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1264011ead2SAneesh Kumar K.V 
127bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
128bccacf6cSAneesh Kumar K.V         return -EINTR;
129bccacf6cSAneesh Kumar K.V     }
130532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1314011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1324011ead2SAneesh Kumar K.V         {
1332289be19SAneesh Kumar K.V             err = s->ops->utimensat(&s->ctx, path, times);
1344011ead2SAneesh Kumar K.V             if (err < 0) {
1354011ead2SAneesh Kumar K.V                 err = -errno;
1364011ead2SAneesh Kumar K.V             }
1374011ead2SAneesh Kumar K.V         });
138532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1394011ead2SAneesh Kumar K.V     return err;
1404011ead2SAneesh Kumar K.V }
1414011ead2SAneesh Kumar K.V 
v9fs_co_chown(V9fsPDU * pdu,V9fsPath * path,uid_t uid,gid_t gid)1425bdade66SGreg Kurz int coroutine_fn v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid,
1435bdade66SGreg Kurz                                gid_t gid)
1444011ead2SAneesh Kumar K.V {
1454011ead2SAneesh Kumar K.V     int err;
1464011ead2SAneesh Kumar K.V     FsCred cred;
147bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1484011ead2SAneesh Kumar K.V 
149bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
150bccacf6cSAneesh Kumar K.V         return -EINTR;
151bccacf6cSAneesh Kumar K.V     }
1524011ead2SAneesh Kumar K.V     cred_init(&cred);
1534011ead2SAneesh Kumar K.V     cred.fc_uid = uid;
1544011ead2SAneesh Kumar K.V     cred.fc_gid = gid;
155532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1564011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1574011ead2SAneesh Kumar K.V         {
1582289be19SAneesh Kumar K.V             err = s->ops->chown(&s->ctx, path, &cred);
1594011ead2SAneesh Kumar K.V             if (err < 0) {
1604011ead2SAneesh Kumar K.V                 err = -errno;
1614011ead2SAneesh Kumar K.V             }
1624011ead2SAneesh Kumar K.V         });
163532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1644011ead2SAneesh Kumar K.V     return err;
1654011ead2SAneesh Kumar K.V }
1664011ead2SAneesh Kumar K.V 
v9fs_co_truncate(V9fsPDU * pdu,V9fsPath * path,off_t size)1675bdade66SGreg Kurz int coroutine_fn v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size)
1684011ead2SAneesh Kumar K.V {
1694011ead2SAneesh Kumar K.V     int err;
170bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
1714011ead2SAneesh Kumar K.V 
172bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
173bccacf6cSAneesh Kumar K.V         return -EINTR;
174bccacf6cSAneesh Kumar K.V     }
175532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
1764011ead2SAneesh Kumar K.V     v9fs_co_run_in_worker(
1774011ead2SAneesh Kumar K.V         {
1782289be19SAneesh Kumar K.V             err = s->ops->truncate(&s->ctx, path, size);
1794011ead2SAneesh Kumar K.V             if (err < 0) {
1804011ead2SAneesh Kumar K.V                 err = -errno;
1814011ead2SAneesh Kumar K.V             }
1824011ead2SAneesh Kumar K.V         });
183532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
1844011ead2SAneesh Kumar K.V     return err;
1854011ead2SAneesh Kumar K.V }
18600ace8c5SAneesh Kumar K.V 
v9fs_co_mknod(V9fsPDU * pdu,V9fsFidState * fidp,V9fsString * name,uid_t uid,gid_t gid,dev_t dev,mode_t mode,struct stat * stbuf)1875bdade66SGreg Kurz int coroutine_fn v9fs_co_mknod(V9fsPDU *pdu, V9fsFidState *fidp,
1885bdade66SGreg Kurz                                V9fsString *name, uid_t uid, gid_t gid,
1895bdade66SGreg Kurz                                dev_t dev, mode_t mode, struct stat *stbuf)
19000ace8c5SAneesh Kumar K.V {
19100ace8c5SAneesh Kumar K.V     int err;
1922289be19SAneesh Kumar K.V     V9fsPath path;
19300ace8c5SAneesh Kumar K.V     FsCred cred;
194bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
19500ace8c5SAneesh Kumar K.V 
196bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
197bccacf6cSAneesh Kumar K.V         return -EINTR;
198bccacf6cSAneesh Kumar K.V     }
19900ace8c5SAneesh Kumar K.V     cred_init(&cred);
20000ace8c5SAneesh Kumar K.V     cred.fc_uid  = uid;
20100ace8c5SAneesh Kumar K.V     cred.fc_gid  = gid;
20200ace8c5SAneesh Kumar K.V     cred.fc_mode = mode;
20300ace8c5SAneesh Kumar K.V     cred.fc_rdev = dev;
204532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
20500ace8c5SAneesh Kumar K.V     v9fs_co_run_in_worker(
20600ace8c5SAneesh Kumar K.V         {
2072289be19SAneesh Kumar K.V             err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred);
20802cb7f3aSAneesh Kumar K.V             if (err < 0) {
20902cb7f3aSAneesh Kumar K.V                 err = -errno;
21002cb7f3aSAneesh Kumar K.V             } else {
2112289be19SAneesh Kumar K.V                 v9fs_path_init(&path);
2122289be19SAneesh Kumar K.V                 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
2132289be19SAneesh Kumar K.V                 if (!err) {
2142289be19SAneesh Kumar K.V                     err = s->ops->lstat(&s->ctx, &path, stbuf);
21500ace8c5SAneesh Kumar K.V                     if (err < 0) {
21600ace8c5SAneesh Kumar K.V                         err = -errno;
21700ace8c5SAneesh Kumar K.V                     }
21802cb7f3aSAneesh Kumar K.V                 }
2192289be19SAneesh Kumar K.V                 v9fs_path_free(&path);
2202289be19SAneesh Kumar K.V             }
22100ace8c5SAneesh Kumar K.V         });
222532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
22300ace8c5SAneesh Kumar K.V     return err;
22400ace8c5SAneesh Kumar K.V }
225b4b1537bSVenkateswararao Jujjuri 
2262289be19SAneesh Kumar K.V /* Only works with path name based fid */
v9fs_co_remove(V9fsPDU * pdu,V9fsPath * path)2275bdade66SGreg Kurz int coroutine_fn v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path)
228b4b1537bSVenkateswararao Jujjuri {
229b4b1537bSVenkateswararao Jujjuri     int err;
230bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
231b4b1537bSVenkateswararao Jujjuri 
232bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
233bccacf6cSAneesh Kumar K.V         return -EINTR;
234bccacf6cSAneesh Kumar K.V     }
235532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
236b4b1537bSVenkateswararao Jujjuri     v9fs_co_run_in_worker(
237b4b1537bSVenkateswararao Jujjuri         {
238b4b1537bSVenkateswararao Jujjuri             err = s->ops->remove(&s->ctx, path->data);
239b4b1537bSVenkateswararao Jujjuri             if (err < 0) {
240b4b1537bSVenkateswararao Jujjuri                 err = -errno;
241b4b1537bSVenkateswararao Jujjuri             }
242b4b1537bSVenkateswararao Jujjuri         });
243532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
244b4b1537bSVenkateswararao Jujjuri     return err;
245b4b1537bSVenkateswararao Jujjuri }
2462a487e05SAneesh Kumar K.V 
v9fs_co_unlinkat(V9fsPDU * pdu,V9fsPath * path,V9fsString * name,int flags)2475bdade66SGreg Kurz int coroutine_fn v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path,
2485bdade66SGreg Kurz                                   V9fsString *name, int flags)
2492289be19SAneesh Kumar K.V {
2502289be19SAneesh Kumar K.V     int err;
251bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
2522289be19SAneesh Kumar K.V 
253bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
254bccacf6cSAneesh Kumar K.V         return -EINTR;
255bccacf6cSAneesh Kumar K.V     }
256532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
2572289be19SAneesh Kumar K.V     v9fs_co_run_in_worker(
2582289be19SAneesh Kumar K.V         {
2592289be19SAneesh Kumar K.V             err = s->ops->unlinkat(&s->ctx, path, name->data, flags);
2602289be19SAneesh Kumar K.V             if (err < 0) {
2612289be19SAneesh Kumar K.V                 err = -errno;
2622289be19SAneesh Kumar K.V             }
2632289be19SAneesh Kumar K.V         });
264532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
2652289be19SAneesh Kumar K.V     return err;
2662289be19SAneesh Kumar K.V }
2672289be19SAneesh Kumar K.V 
2682289be19SAneesh Kumar K.V /* Only work with path name based fid */
v9fs_co_rename(V9fsPDU * pdu,V9fsPath * oldpath,V9fsPath * newpath)2695bdade66SGreg Kurz int coroutine_fn v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath,
2705bdade66SGreg Kurz                                 V9fsPath *newpath)
2712a487e05SAneesh Kumar K.V {
2722a487e05SAneesh Kumar K.V     int err;
273bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
2742a487e05SAneesh Kumar K.V 
275bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
276bccacf6cSAneesh Kumar K.V         return -EINTR;
277bccacf6cSAneesh Kumar K.V     }
2782a487e05SAneesh Kumar K.V     v9fs_co_run_in_worker(
2792a487e05SAneesh Kumar K.V         {
2802a487e05SAneesh Kumar K.V             err = s->ops->rename(&s->ctx, oldpath->data, newpath->data);
2812a487e05SAneesh Kumar K.V             if (err < 0) {
2822a487e05SAneesh Kumar K.V                 err = -errno;
2832a487e05SAneesh Kumar K.V             }
2842a487e05SAneesh Kumar K.V         });
2852a487e05SAneesh Kumar K.V     return err;
2862a487e05SAneesh Kumar K.V }
28702ac7a34SVenkateswararao Jujjuri 
v9fs_co_renameat(V9fsPDU * pdu,V9fsPath * olddirpath,V9fsString * oldname,V9fsPath * newdirpath,V9fsString * newname)2885bdade66SGreg Kurz int coroutine_fn v9fs_co_renameat(V9fsPDU *pdu, V9fsPath *olddirpath,
2895bdade66SGreg Kurz                                   V9fsString *oldname, V9fsPath *newdirpath,
2905bdade66SGreg Kurz                                   V9fsString *newname)
2912289be19SAneesh Kumar K.V {
2922289be19SAneesh Kumar K.V     int err;
293bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
2942289be19SAneesh Kumar K.V 
295bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
296bccacf6cSAneesh Kumar K.V         return -EINTR;
297bccacf6cSAneesh Kumar K.V     }
2982289be19SAneesh Kumar K.V     v9fs_co_run_in_worker(
2992289be19SAneesh Kumar K.V         {
3002289be19SAneesh Kumar K.V             err = s->ops->renameat(&s->ctx, olddirpath, oldname->data,
3012289be19SAneesh Kumar K.V                                    newdirpath, newname->data);
3022289be19SAneesh Kumar K.V             if (err < 0) {
3032289be19SAneesh Kumar K.V                 err = -errno;
3042289be19SAneesh Kumar K.V             }
3052289be19SAneesh Kumar K.V         });
3062289be19SAneesh Kumar K.V     return err;
3072289be19SAneesh Kumar K.V }
3082289be19SAneesh Kumar K.V 
v9fs_co_symlink(V9fsPDU * pdu,V9fsFidState * dfidp,V9fsString * name,const char * oldpath,gid_t gid,struct stat * stbuf)3095bdade66SGreg Kurz int coroutine_fn v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp,
3105bdade66SGreg Kurz                                  V9fsString *name, const char *oldpath,
3115bdade66SGreg Kurz                                  gid_t gid, struct stat *stbuf)
31202ac7a34SVenkateswararao Jujjuri {
31302ac7a34SVenkateswararao Jujjuri     int err;
31402ac7a34SVenkateswararao Jujjuri     FsCred cred;
3152289be19SAneesh Kumar K.V     V9fsPath path;
316bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
31702cb7f3aSAneesh Kumar K.V 
318bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
319bccacf6cSAneesh Kumar K.V         return -EINTR;
320bccacf6cSAneesh Kumar K.V     }
32102ac7a34SVenkateswararao Jujjuri     cred_init(&cred);
32202cb7f3aSAneesh Kumar K.V     cred.fc_uid = dfidp->uid;
32302ac7a34SVenkateswararao Jujjuri     cred.fc_gid = gid;
32402ac7a34SVenkateswararao Jujjuri     cred.fc_mode = 0777;
325532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
32602ac7a34SVenkateswararao Jujjuri     v9fs_co_run_in_worker(
32702ac7a34SVenkateswararao Jujjuri         {
3282289be19SAneesh Kumar K.V             err = s->ops->symlink(&s->ctx, oldpath, &dfidp->path,
3292289be19SAneesh Kumar K.V                                   name->data, &cred);
33002cb7f3aSAneesh Kumar K.V             if (err < 0) {
33102cb7f3aSAneesh Kumar K.V                 err = -errno;
33202cb7f3aSAneesh Kumar K.V             } else {
3332289be19SAneesh Kumar K.V                 v9fs_path_init(&path);
3342289be19SAneesh Kumar K.V                 err = v9fs_name_to_path(s, &dfidp->path, name->data, &path);
3352289be19SAneesh Kumar K.V                 if (!err) {
3362289be19SAneesh Kumar K.V                     err = s->ops->lstat(&s->ctx, &path, stbuf);
33702ac7a34SVenkateswararao Jujjuri                     if (err < 0) {
33802ac7a34SVenkateswararao Jujjuri                         err = -errno;
33902ac7a34SVenkateswararao Jujjuri                     }
34002cb7f3aSAneesh Kumar K.V                 }
3412289be19SAneesh Kumar K.V                 v9fs_path_free(&path);
3422289be19SAneesh Kumar K.V             }
34302ac7a34SVenkateswararao Jujjuri         });
344532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
3452289be19SAneesh Kumar K.V     return err;
3462289be19SAneesh Kumar K.V }
3472289be19SAneesh Kumar K.V 
3482289be19SAneesh Kumar K.V /*
3492289be19SAneesh Kumar K.V  * For path name based fid we don't block. So we can
3502289be19SAneesh Kumar K.V  * directly call the fs driver ops.
3512289be19SAneesh Kumar K.V  */
v9fs_co_name_to_path(V9fsPDU * pdu,V9fsPath * dirpath,const char * name,V9fsPath * path)3525bdade66SGreg Kurz int coroutine_fn v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath,
3532289be19SAneesh Kumar K.V                                       const char *name, V9fsPath *path)
3542289be19SAneesh Kumar K.V {
3552289be19SAneesh Kumar K.V     int err;
356bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
357532decb7SAneesh Kumar K.V 
358c98f1d4aSAneesh Kumar K.V     if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
3592289be19SAneesh Kumar K.V         err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
3602289be19SAneesh Kumar K.V         if (err < 0) {
3612289be19SAneesh Kumar K.V             err = -errno;
3622289be19SAneesh Kumar K.V         }
363532decb7SAneesh Kumar K.V     } else {
364bccacf6cSAneesh Kumar K.V         if (v9fs_request_cancelled(pdu)) {
365bccacf6cSAneesh Kumar K.V             return -EINTR;
366bccacf6cSAneesh Kumar K.V         }
367532decb7SAneesh Kumar K.V         v9fs_co_run_in_worker(
368532decb7SAneesh Kumar K.V             {
369532decb7SAneesh Kumar K.V                 err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
370532decb7SAneesh Kumar K.V                 if (err < 0) {
371532decb7SAneesh Kumar K.V                     err = -errno;
372532decb7SAneesh Kumar K.V                 }
373532decb7SAneesh Kumar K.V             });
374532decb7SAneesh Kumar K.V     }
37502ac7a34SVenkateswararao Jujjuri     return err;
37602ac7a34SVenkateswararao Jujjuri }
377