xref: /openbmc/qemu/hw/9pfs/coxattr.c (revision 1580b897)
1 /*
2  * 9p backend
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.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 /*
15  * Not so fast! You might want to read the 9p developer docs first:
16  * https://wiki.qemu.org/Documentation/9p
17  */
18 
19 #include "qemu/osdep.h"
20 #include "fsdev/qemu-fsdev.h"
21 #include "qemu/thread.h"
22 #include "qemu/coroutine.h"
23 #include "qemu/main-loop.h"
24 #include "coth.h"
25 
26 int coroutine_fn v9fs_co_llistxattr(V9fsPDU *pdu, V9fsPath *path, void *value,
27                                     size_t size)
28 {
29     int err;
30     V9fsState *s = pdu->s;
31 
32     if (v9fs_request_cancelled(pdu)) {
33         return -EINTR;
34     }
35     v9fs_path_read_lock(s);
36     v9fs_co_run_in_worker(
37         {
38             err = s->ops->llistxattr(&s->ctx, path, value, size);
39             if (err < 0) {
40                 err = -errno;
41             }
42         });
43     v9fs_path_unlock(s);
44     return err;
45 }
46 
47 int coroutine_fn v9fs_co_lgetxattr(V9fsPDU *pdu, V9fsPath *path,
48                                    V9fsString *xattr_name, void *value,
49                                    size_t size)
50 {
51     int err;
52     V9fsState *s = pdu->s;
53 
54     if (v9fs_request_cancelled(pdu)) {
55         return -EINTR;
56     }
57     v9fs_path_read_lock(s);
58     v9fs_co_run_in_worker(
59         {
60             err = s->ops->lgetxattr(&s->ctx, path,
61                                     xattr_name->data,
62                                     value, size);
63             if (err < 0) {
64                 err = -errno;
65             }
66         });
67     v9fs_path_unlock(s);
68     return err;
69 }
70 
71 int coroutine_fn v9fs_co_lsetxattr(V9fsPDU *pdu, V9fsPath *path,
72                                    V9fsString *xattr_name, void *value,
73                                    size_t size, int flags)
74 {
75     int err;
76     V9fsState *s = pdu->s;
77 
78     if (v9fs_request_cancelled(pdu)) {
79         return -EINTR;
80     }
81     v9fs_path_read_lock(s);
82     v9fs_co_run_in_worker(
83         {
84             err = s->ops->lsetxattr(&s->ctx, path,
85                                     xattr_name->data, value,
86                                     size, flags);
87             if (err < 0) {
88                 err = -errno;
89             }
90         });
91     v9fs_path_unlock(s);
92     return err;
93 }
94 
95 int coroutine_fn v9fs_co_lremovexattr(V9fsPDU *pdu, V9fsPath *path,
96                                       V9fsString *xattr_name)
97 {
98     int err;
99     V9fsState *s = pdu->s;
100 
101     if (v9fs_request_cancelled(pdu)) {
102         return -EINTR;
103     }
104     v9fs_path_read_lock(s);
105     v9fs_co_run_in_worker(
106         {
107             err = s->ops->lremovexattr(&s->ctx, path, xattr_name->data);
108             if (err < 0) {
109                 err = -errno;
110             }
111         });
112     v9fs_path_unlock(s);
113     return err;
114 }
115