xref: /openbmc/qemu/hw/9pfs/coxattr.c (revision 59a3a1c0)
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 #include "qemu/osdep.h"
15 #include "fsdev/qemu-fsdev.h"
16 #include "qemu/thread.h"
17 #include "qemu/coroutine.h"
18 #include "qemu/main-loop.h"
19 #include "coth.h"
20 
21 int coroutine_fn v9fs_co_llistxattr(V9fsPDU *pdu, V9fsPath *path, void *value,
22                                     size_t size)
23 {
24     int err;
25     V9fsState *s = pdu->s;
26 
27     if (v9fs_request_cancelled(pdu)) {
28         return -EINTR;
29     }
30     v9fs_path_read_lock(s);
31     v9fs_co_run_in_worker(
32         {
33             err = s->ops->llistxattr(&s->ctx, path, value, size);
34             if (err < 0) {
35                 err = -errno;
36             }
37         });
38     v9fs_path_unlock(s);
39     return err;
40 }
41 
42 int coroutine_fn v9fs_co_lgetxattr(V9fsPDU *pdu, V9fsPath *path,
43                                    V9fsString *xattr_name, void *value,
44                                    size_t size)
45 {
46     int err;
47     V9fsState *s = pdu->s;
48 
49     if (v9fs_request_cancelled(pdu)) {
50         return -EINTR;
51     }
52     v9fs_path_read_lock(s);
53     v9fs_co_run_in_worker(
54         {
55             err = s->ops->lgetxattr(&s->ctx, path,
56                                     xattr_name->data,
57                                     value, size);
58             if (err < 0) {
59                 err = -errno;
60             }
61         });
62     v9fs_path_unlock(s);
63     return err;
64 }
65 
66 int coroutine_fn v9fs_co_lsetxattr(V9fsPDU *pdu, V9fsPath *path,
67                                    V9fsString *xattr_name, void *value,
68                                    size_t size, int flags)
69 {
70     int err;
71     V9fsState *s = pdu->s;
72 
73     if (v9fs_request_cancelled(pdu)) {
74         return -EINTR;
75     }
76     v9fs_path_read_lock(s);
77     v9fs_co_run_in_worker(
78         {
79             err = s->ops->lsetxattr(&s->ctx, path,
80                                     xattr_name->data, value,
81                                     size, flags);
82             if (err < 0) {
83                 err = -errno;
84             }
85         });
86     v9fs_path_unlock(s);
87     return err;
88 }
89 
90 int coroutine_fn v9fs_co_lremovexattr(V9fsPDU *pdu, V9fsPath *path,
91                                       V9fsString *xattr_name)
92 {
93     int err;
94     V9fsState *s = pdu->s;
95 
96     if (v9fs_request_cancelled(pdu)) {
97         return -EINTR;
98     }
99     v9fs_path_read_lock(s);
100     v9fs_co_run_in_worker(
101         {
102             err = s->ops->lremovexattr(&s->ctx, path, xattr_name->data);
103             if (err < 0) {
104                 err = -errno;
105             }
106         });
107     v9fs_path_unlock(s);
108     return err;
109 }
110