root / hw / 9pfs / codir.c @ 77eec1b3
History | View | Annotate | Download (3.7 kB)
1 | dcb9dbe3 | Aneesh Kumar K.V | |
---|---|---|---|
2 | dcb9dbe3 | Aneesh Kumar K.V | /*
|
3 | dcb9dbe3 | Aneesh Kumar K.V | * Virtio 9p backend
|
4 | dcb9dbe3 | Aneesh Kumar K.V | *
|
5 | dcb9dbe3 | Aneesh Kumar K.V | * Copyright IBM, Corp. 2011
|
6 | dcb9dbe3 | Aneesh Kumar K.V | *
|
7 | dcb9dbe3 | Aneesh Kumar K.V | * Authors:
|
8 | dcb9dbe3 | Aneesh Kumar K.V | * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
|
9 | dcb9dbe3 | Aneesh Kumar K.V | *
|
10 | dcb9dbe3 | Aneesh Kumar K.V | * This work is licensed under the terms of the GNU GPL, version 2. See
|
11 | dcb9dbe3 | Aneesh Kumar K.V | * the COPYING file in the top-level directory.
|
12 | dcb9dbe3 | Aneesh Kumar K.V | *
|
13 | dcb9dbe3 | Aneesh Kumar K.V | */
|
14 | dcb9dbe3 | Aneesh Kumar K.V | |
15 | dcb9dbe3 | Aneesh Kumar K.V | #include "fsdev/qemu-fsdev.h" |
16 | dcb9dbe3 | Aneesh Kumar K.V | #include "qemu-thread.h" |
17 | dcb9dbe3 | Aneesh Kumar K.V | #include "qemu-coroutine.h" |
18 | dcb9dbe3 | Aneesh Kumar K.V | #include "virtio-9p-coth.h" |
19 | dcb9dbe3 | Aneesh Kumar K.V | |
20 | bccacf6c | Aneesh Kumar K.V | int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent *dent, |
21 | 5f524c1e | Harsh Prateek Bora | struct dirent **result)
|
22 | dcb9dbe3 | Aneesh Kumar K.V | { |
23 | dcb9dbe3 | Aneesh Kumar K.V | int err;
|
24 | bccacf6c | Aneesh Kumar K.V | V9fsState *s = pdu->s; |
25 | dcb9dbe3 | Aneesh Kumar K.V | |
26 | bccacf6c | Aneesh Kumar K.V | if (v9fs_request_cancelled(pdu)) {
|
27 | bccacf6c | Aneesh Kumar K.V | return -EINTR;
|
28 | bccacf6c | Aneesh Kumar K.V | } |
29 | dcb9dbe3 | Aneesh Kumar K.V | v9fs_co_run_in_worker( |
30 | dcb9dbe3 | Aneesh Kumar K.V | { |
31 | dcb9dbe3 | Aneesh Kumar K.V | errno = 0;
|
32 | cc720ddb | Aneesh Kumar K.V | err = s->ops->readdir_r(&s->ctx, &fidp->fs, dent, result); |
33 | 5f524c1e | Harsh Prateek Bora | if (!*result && errno) {
|
34 | dcb9dbe3 | Aneesh Kumar K.V | err = -errno; |
35 | dcb9dbe3 | Aneesh Kumar K.V | } else {
|
36 | dcb9dbe3 | Aneesh Kumar K.V | err = 0;
|
37 | dcb9dbe3 | Aneesh Kumar K.V | } |
38 | dcb9dbe3 | Aneesh Kumar K.V | }); |
39 | dcb9dbe3 | Aneesh Kumar K.V | return err;
|
40 | dcb9dbe3 | Aneesh Kumar K.V | } |
41 | dcb9dbe3 | Aneesh Kumar K.V | |
42 | bccacf6c | Aneesh Kumar K.V | off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp) |
43 | dcb9dbe3 | Aneesh Kumar K.V | { |
44 | dcb9dbe3 | Aneesh Kumar K.V | off_t err; |
45 | bccacf6c | Aneesh Kumar K.V | V9fsState *s = pdu->s; |
46 | dcb9dbe3 | Aneesh Kumar K.V | |
47 | bccacf6c | Aneesh Kumar K.V | if (v9fs_request_cancelled(pdu)) {
|
48 | bccacf6c | Aneesh Kumar K.V | return -EINTR;
|
49 | bccacf6c | Aneesh Kumar K.V | } |
50 | dcb9dbe3 | Aneesh Kumar K.V | v9fs_co_run_in_worker( |
51 | dcb9dbe3 | Aneesh Kumar K.V | { |
52 | cc720ddb | Aneesh Kumar K.V | err = s->ops->telldir(&s->ctx, &fidp->fs); |
53 | dcb9dbe3 | Aneesh Kumar K.V | if (err < 0) { |
54 | dcb9dbe3 | Aneesh Kumar K.V | err = -errno; |
55 | dcb9dbe3 | Aneesh Kumar K.V | } |
56 | dcb9dbe3 | Aneesh Kumar K.V | }); |
57 | dcb9dbe3 | Aneesh Kumar K.V | return err;
|
58 | dcb9dbe3 | Aneesh Kumar K.V | } |
59 | dcb9dbe3 | Aneesh Kumar K.V | |
60 | bccacf6c | Aneesh Kumar K.V | void v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp, off_t offset)
|
61 | dcb9dbe3 | Aneesh Kumar K.V | { |
62 | bccacf6c | Aneesh Kumar K.V | V9fsState *s = pdu->s; |
63 | bccacf6c | Aneesh Kumar K.V | if (v9fs_request_cancelled(pdu)) {
|
64 | bccacf6c | Aneesh Kumar K.V | return;
|
65 | bccacf6c | Aneesh Kumar K.V | } |
66 | dcb9dbe3 | Aneesh Kumar K.V | v9fs_co_run_in_worker( |
67 | dcb9dbe3 | Aneesh Kumar K.V | { |
68 | cc720ddb | Aneesh Kumar K.V | s->ops->seekdir(&s->ctx, &fidp->fs, offset); |
69 | dcb9dbe3 | Aneesh Kumar K.V | }); |
70 | dcb9dbe3 | Aneesh Kumar K.V | } |
71 | dcb9dbe3 | Aneesh Kumar K.V | |
72 | bccacf6c | Aneesh Kumar K.V | void v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp)
|
73 | dcb9dbe3 | Aneesh Kumar K.V | { |
74 | bccacf6c | Aneesh Kumar K.V | V9fsState *s = pdu->s; |
75 | bccacf6c | Aneesh Kumar K.V | if (v9fs_request_cancelled(pdu)) {
|
76 | bccacf6c | Aneesh Kumar K.V | return;
|
77 | bccacf6c | Aneesh Kumar K.V | } |
78 | dcb9dbe3 | Aneesh Kumar K.V | v9fs_co_run_in_worker( |
79 | dcb9dbe3 | Aneesh Kumar K.V | { |
80 | cc720ddb | Aneesh Kumar K.V | s->ops->rewinddir(&s->ctx, &fidp->fs); |
81 | dcb9dbe3 | Aneesh Kumar K.V | }); |
82 | dcb9dbe3 | Aneesh Kumar K.V | } |
83 | d0884642 | Venkateswararao Jujjuri | |
84 | bccacf6c | Aneesh Kumar K.V | int v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name,
|
85 | 02cb7f3a | Aneesh Kumar K.V | mode_t mode, uid_t uid, gid_t gid, struct stat *stbuf)
|
86 | d0884642 | Venkateswararao Jujjuri | { |
87 | d0884642 | Venkateswararao Jujjuri | int err;
|
88 | d0884642 | Venkateswararao Jujjuri | FsCred cred; |
89 | 2289be19 | Aneesh Kumar K.V | V9fsPath path; |
90 | bccacf6c | Aneesh Kumar K.V | V9fsState *s = pdu->s; |
91 | d0884642 | Venkateswararao Jujjuri | |
92 | bccacf6c | Aneesh Kumar K.V | if (v9fs_request_cancelled(pdu)) {
|
93 | bccacf6c | Aneesh Kumar K.V | return -EINTR;;
|
94 | bccacf6c | Aneesh Kumar K.V | } |
95 | d0884642 | Venkateswararao Jujjuri | cred_init(&cred); |
96 | d0884642 | Venkateswararao Jujjuri | cred.fc_mode = mode; |
97 | d0884642 | Venkateswararao Jujjuri | cred.fc_uid = uid; |
98 | d0884642 | Venkateswararao Jujjuri | cred.fc_gid = gid; |
99 | 532decb7 | Aneesh Kumar K.V | v9fs_path_read_lock(s); |
100 | d0884642 | Venkateswararao Jujjuri | v9fs_co_run_in_worker( |
101 | d0884642 | Venkateswararao Jujjuri | { |
102 | 2289be19 | Aneesh Kumar K.V | err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred); |
103 | d0884642 | Venkateswararao Jujjuri | if (err < 0) { |
104 | d0884642 | Venkateswararao Jujjuri | err = -errno; |
105 | 02cb7f3a | Aneesh Kumar K.V | } else {
|
106 | 2289be19 | Aneesh Kumar K.V | v9fs_path_init(&path); |
107 | 2289be19 | Aneesh Kumar K.V | err = v9fs_name_to_path(s, &fidp->path, name->data, &path); |
108 | 2289be19 | Aneesh Kumar K.V | if (!err) {
|
109 | 2289be19 | Aneesh Kumar K.V | err = s->ops->lstat(&s->ctx, &path, stbuf); |
110 | 2289be19 | Aneesh Kumar K.V | if (err < 0) { |
111 | 2289be19 | Aneesh Kumar K.V | err = -errno; |
112 | 2289be19 | Aneesh Kumar K.V | } |
113 | 02cb7f3a | Aneesh Kumar K.V | } |
114 | 2289be19 | Aneesh Kumar K.V | v9fs_path_free(&path); |
115 | d0884642 | Venkateswararao Jujjuri | } |
116 | d0884642 | Venkateswararao Jujjuri | }); |
117 | 532decb7 | Aneesh Kumar K.V | v9fs_path_unlock(s); |
118 | d0884642 | Venkateswararao Jujjuri | return err;
|
119 | d0884642 | Venkateswararao Jujjuri | } |
120 | f6b7f0ab | Aneesh Kumar K.V | |
121 | bccacf6c | Aneesh Kumar K.V | int v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp)
|
122 | f6b7f0ab | Aneesh Kumar K.V | { |
123 | f6b7f0ab | Aneesh Kumar K.V | int err;
|
124 | bccacf6c | Aneesh Kumar K.V | V9fsState *s = pdu->s; |
125 | f6b7f0ab | Aneesh Kumar K.V | |
126 | bccacf6c | Aneesh Kumar K.V | if (v9fs_request_cancelled(pdu)) {
|
127 | bccacf6c | Aneesh Kumar K.V | return -EINTR;;
|
128 | bccacf6c | Aneesh Kumar K.V | } |
129 | 532decb7 | Aneesh Kumar K.V | v9fs_path_read_lock(s); |
130 | f6b7f0ab | Aneesh Kumar K.V | v9fs_co_run_in_worker( |
131 | f6b7f0ab | Aneesh Kumar K.V | { |
132 | cc720ddb | Aneesh Kumar K.V | err = s->ops->opendir(&s->ctx, &fidp->path, &fidp->fs); |
133 | cc720ddb | Aneesh Kumar K.V | if (err < 0) { |
134 | f6b7f0ab | Aneesh Kumar K.V | err = -errno; |
135 | f6b7f0ab | Aneesh Kumar K.V | } else {
|
136 | f6b7f0ab | Aneesh Kumar K.V | err = 0;
|
137 | f6b7f0ab | Aneesh Kumar K.V | } |
138 | f6b7f0ab | Aneesh Kumar K.V | }); |
139 | 532decb7 | Aneesh Kumar K.V | v9fs_path_unlock(s); |
140 | 95f65511 | Aneesh Kumar K.V | if (!err) {
|
141 | 95f65511 | Aneesh Kumar K.V | total_open_fd++; |
142 | 95f65511 | Aneesh Kumar K.V | if (total_open_fd > open_fd_hw) {
|
143 | bccacf6c | Aneesh Kumar K.V | v9fs_reclaim_fd(pdu); |
144 | 95f65511 | Aneesh Kumar K.V | } |
145 | 95f65511 | Aneesh Kumar K.V | } |
146 | f6b7f0ab | Aneesh Kumar K.V | return err;
|
147 | f6b7f0ab | Aneesh Kumar K.V | } |
148 | bed4352c | Aneesh Kumar K.V | |
149 | cc720ddb | Aneesh Kumar K.V | int v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)
|
150 | bed4352c | Aneesh Kumar K.V | { |
151 | bed4352c | Aneesh Kumar K.V | int err;
|
152 | bccacf6c | Aneesh Kumar K.V | V9fsState *s = pdu->s; |
153 | bed4352c | Aneesh Kumar K.V | |
154 | bccacf6c | Aneesh Kumar K.V | if (v9fs_request_cancelled(pdu)) {
|
155 | bccacf6c | Aneesh Kumar K.V | return -EINTR;;
|
156 | bccacf6c | Aneesh Kumar K.V | } |
157 | bed4352c | Aneesh Kumar K.V | v9fs_co_run_in_worker( |
158 | bed4352c | Aneesh Kumar K.V | { |
159 | cc720ddb | Aneesh Kumar K.V | err = s->ops->closedir(&s->ctx, fs); |
160 | bed4352c | Aneesh Kumar K.V | if (err < 0) { |
161 | bed4352c | Aneesh Kumar K.V | err = -errno; |
162 | bed4352c | Aneesh Kumar K.V | } |
163 | bed4352c | Aneesh Kumar K.V | }); |
164 | 95f65511 | Aneesh Kumar K.V | if (!err) {
|
165 | 95f65511 | Aneesh Kumar K.V | total_open_fd--; |
166 | 95f65511 | Aneesh Kumar K.V | } |
167 | bed4352c | Aneesh Kumar K.V | return err;
|
168 | bed4352c | Aneesh Kumar K.V | } |