xref: /openbmc/qemu/hw/9pfs/coxattr.c (revision 23792478)
11ceffa54SAneesh Kumar K.V /*
2af8b38b0SGreg Kurz  * 9p backend
31ceffa54SAneesh Kumar K.V  *
41ceffa54SAneesh Kumar K.V  * Copyright IBM, Corp. 2011
51ceffa54SAneesh Kumar K.V  *
61ceffa54SAneesh Kumar K.V  * Authors:
71ceffa54SAneesh Kumar K.V  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
81ceffa54SAneesh Kumar K.V  *
91ceffa54SAneesh Kumar K.V  * This work is licensed under the terms of the GNU GPL, version 2.  See
101ceffa54SAneesh Kumar K.V  * the COPYING file in the top-level directory.
111ceffa54SAneesh Kumar K.V  *
121ceffa54SAneesh Kumar K.V  */
131ceffa54SAneesh Kumar K.V 
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"
201ceffa54SAneesh Kumar K.V #include "fsdev/qemu-fsdev.h"
211de7afc9SPaolo Bonzini #include "qemu/thread.h"
22db725815SMarkus Armbruster #include "qemu/main-loop.h"
23fe52840cSWei Liu #include "coth.h"
241ceffa54SAneesh Kumar K.V 
v9fs_co_llistxattr(V9fsPDU * pdu,V9fsPath * path,void * value,size_t size)255bdade66SGreg Kurz int coroutine_fn v9fs_co_llistxattr(V9fsPDU *pdu, V9fsPath *path, void *value,
265bdade66SGreg Kurz                                     size_t size)
271ceffa54SAneesh Kumar K.V {
281ceffa54SAneesh Kumar K.V     int err;
29bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
301ceffa54SAneesh Kumar K.V 
31bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
32bccacf6cSAneesh Kumar K.V         return -EINTR;
33bccacf6cSAneesh Kumar K.V     }
34532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
351ceffa54SAneesh Kumar K.V     v9fs_co_run_in_worker(
361ceffa54SAneesh Kumar K.V         {
372289be19SAneesh Kumar K.V             err = s->ops->llistxattr(&s->ctx, path, value, size);
381ceffa54SAneesh Kumar K.V             if (err < 0) {
391ceffa54SAneesh Kumar K.V                 err = -errno;
401ceffa54SAneesh Kumar K.V             }
411ceffa54SAneesh Kumar K.V         });
42532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
431ceffa54SAneesh Kumar K.V     return err;
441ceffa54SAneesh Kumar K.V }
451ceffa54SAneesh Kumar K.V 
v9fs_co_lgetxattr(V9fsPDU * pdu,V9fsPath * path,V9fsString * xattr_name,void * value,size_t size)465bdade66SGreg Kurz int coroutine_fn v9fs_co_lgetxattr(V9fsPDU *pdu, V9fsPath *path,
475bdade66SGreg Kurz                                    V9fsString *xattr_name, void *value,
485bdade66SGreg Kurz                                    size_t size)
491ceffa54SAneesh Kumar K.V {
501ceffa54SAneesh Kumar K.V     int err;
51bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
521ceffa54SAneesh Kumar K.V 
53bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
54bccacf6cSAneesh Kumar K.V         return -EINTR;
55bccacf6cSAneesh Kumar K.V     }
56532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
571ceffa54SAneesh Kumar K.V     v9fs_co_run_in_worker(
581ceffa54SAneesh Kumar K.V         {
592289be19SAneesh Kumar K.V             err = s->ops->lgetxattr(&s->ctx, path,
601ceffa54SAneesh Kumar K.V                                     xattr_name->data,
611ceffa54SAneesh Kumar K.V                                     value, size);
621ceffa54SAneesh Kumar K.V             if (err < 0) {
631ceffa54SAneesh Kumar K.V                 err = -errno;
641ceffa54SAneesh Kumar K.V             }
651ceffa54SAneesh Kumar K.V         });
66532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
671ceffa54SAneesh Kumar K.V     return err;
681ceffa54SAneesh Kumar K.V }
69bed4352cSAneesh Kumar K.V 
v9fs_co_lsetxattr(V9fsPDU * pdu,V9fsPath * path,V9fsString * xattr_name,void * value,size_t size,int flags)705bdade66SGreg Kurz int coroutine_fn v9fs_co_lsetxattr(V9fsPDU *pdu, V9fsPath *path,
71bed4352cSAneesh Kumar K.V                                    V9fsString *xattr_name, void *value,
72bed4352cSAneesh Kumar K.V                                    size_t size, int flags)
73bed4352cSAneesh Kumar K.V {
74bed4352cSAneesh Kumar K.V     int err;
75bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
76bed4352cSAneesh Kumar K.V 
77bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
78bccacf6cSAneesh Kumar K.V         return -EINTR;
79bccacf6cSAneesh Kumar K.V     }
80532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
81bed4352cSAneesh Kumar K.V     v9fs_co_run_in_worker(
82bed4352cSAneesh Kumar K.V         {
832289be19SAneesh Kumar K.V             err = s->ops->lsetxattr(&s->ctx, path,
84bed4352cSAneesh Kumar K.V                                     xattr_name->data, value,
85bed4352cSAneesh Kumar K.V                                     size, flags);
86bed4352cSAneesh Kumar K.V             if (err < 0) {
87bed4352cSAneesh Kumar K.V                 err = -errno;
88bed4352cSAneesh Kumar K.V             }
89bed4352cSAneesh Kumar K.V         });
90532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
91bed4352cSAneesh Kumar K.V     return err;
92bed4352cSAneesh Kumar K.V }
93bed4352cSAneesh Kumar K.V 
v9fs_co_lremovexattr(V9fsPDU * pdu,V9fsPath * path,V9fsString * xattr_name)945bdade66SGreg Kurz int coroutine_fn v9fs_co_lremovexattr(V9fsPDU *pdu, V9fsPath *path,
95bed4352cSAneesh Kumar K.V                                       V9fsString *xattr_name)
96bed4352cSAneesh Kumar K.V {
97bed4352cSAneesh Kumar K.V     int err;
98bccacf6cSAneesh Kumar K.V     V9fsState *s = pdu->s;
99bed4352cSAneesh Kumar K.V 
100bccacf6cSAneesh Kumar K.V     if (v9fs_request_cancelled(pdu)) {
101bccacf6cSAneesh Kumar K.V         return -EINTR;
102bccacf6cSAneesh Kumar K.V     }
103532decb7SAneesh Kumar K.V     v9fs_path_read_lock(s);
104bed4352cSAneesh Kumar K.V     v9fs_co_run_in_worker(
105bed4352cSAneesh Kumar K.V         {
1062289be19SAneesh Kumar K.V             err = s->ops->lremovexattr(&s->ctx, path, xattr_name->data);
107bed4352cSAneesh Kumar K.V             if (err < 0) {
108bed4352cSAneesh Kumar K.V                 err = -errno;
109bed4352cSAneesh Kumar K.V             }
110bed4352cSAneesh Kumar K.V         });
111532decb7SAneesh Kumar K.V     v9fs_path_unlock(s);
112bed4352cSAneesh Kumar K.V     return err;
113bed4352cSAneesh Kumar K.V }
114