Statistics
| Branch: | Revision:

root / hw / 9pfs / cofile.c @ 39f8c32c

History | View | Annotate | Download (6.1 kB)

1 172198d4 Aneesh Kumar K.V
2 172198d4 Aneesh Kumar K.V
/*
3 172198d4 Aneesh Kumar K.V
 * Virtio 9p backend
4 172198d4 Aneesh Kumar K.V
 *
5 172198d4 Aneesh Kumar K.V
 * Copyright IBM, Corp. 2011
6 172198d4 Aneesh Kumar K.V
 *
7 172198d4 Aneesh Kumar K.V
 * Authors:
8 172198d4 Aneesh Kumar K.V
 *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
9 172198d4 Aneesh Kumar K.V
 *
10 172198d4 Aneesh Kumar K.V
 * This work is licensed under the terms of the GNU GPL, version 2.  See
11 172198d4 Aneesh Kumar K.V
 * the COPYING file in the top-level directory.
12 172198d4 Aneesh Kumar K.V
 *
13 172198d4 Aneesh Kumar K.V
 */
14 172198d4 Aneesh Kumar K.V
15 172198d4 Aneesh Kumar K.V
#include "fsdev/qemu-fsdev.h"
16 172198d4 Aneesh Kumar K.V
#include "qemu-thread.h"
17 172198d4 Aneesh Kumar K.V
#include "qemu-coroutine.h"
18 172198d4 Aneesh Kumar K.V
#include "virtio-9p-coth.h"
19 172198d4 Aneesh Kumar K.V
20 e06a765e Harsh Prateek Bora
int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
21 e06a765e Harsh Prateek Bora
                   V9fsStatDotl *v9stat)
22 e06a765e Harsh Prateek Bora
{
23 e06a765e Harsh Prateek Bora
    int err = 0;
24 e06a765e Harsh Prateek Bora
    V9fsState *s = pdu->s;
25 e06a765e Harsh Prateek Bora
26 e06a765e Harsh Prateek Bora
    if (v9fs_request_cancelled(pdu)) {
27 e06a765e Harsh Prateek Bora
        return -EINTR;
28 e06a765e Harsh Prateek Bora
    }
29 e06a765e Harsh Prateek Bora
    if (s->ctx.exops.get_st_gen) {
30 e06a765e Harsh Prateek Bora
        v9fs_path_read_lock(s);
31 e06a765e Harsh Prateek Bora
        v9fs_co_run_in_worker(
32 e06a765e Harsh Prateek Bora
            {
33 e06a765e Harsh Prateek Bora
                err = s->ctx.exops.get_st_gen(&s->ctx, path, st_mode,
34 e06a765e Harsh Prateek Bora
                                              &v9stat->st_gen);
35 e06a765e Harsh Prateek Bora
                if (err < 0) {
36 e06a765e Harsh Prateek Bora
                    err = -errno;
37 e06a765e Harsh Prateek Bora
                }
38 e06a765e Harsh Prateek Bora
            });
39 e06a765e Harsh Prateek Bora
        v9fs_path_unlock(s);
40 e06a765e Harsh Prateek Bora
    }
41 e06a765e Harsh Prateek Bora
    return err;
42 e06a765e Harsh Prateek Bora
}
43 e06a765e Harsh Prateek Bora
44 bccacf6c Aneesh Kumar K.V
int v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf)
45 172198d4 Aneesh Kumar K.V
{
46 172198d4 Aneesh Kumar K.V
    int err;
47 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
48 172198d4 Aneesh Kumar K.V
49 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
50 bccacf6c Aneesh Kumar K.V
        return -EINTR;
51 bccacf6c Aneesh Kumar K.V
    }
52 532decb7 Aneesh Kumar K.V
    v9fs_path_read_lock(s);
53 172198d4 Aneesh Kumar K.V
    v9fs_co_run_in_worker(
54 172198d4 Aneesh Kumar K.V
        {
55 2289be19 Aneesh Kumar K.V
            err = s->ops->lstat(&s->ctx, path, stbuf);
56 172198d4 Aneesh Kumar K.V
            if (err < 0) {
57 172198d4 Aneesh Kumar K.V
                err = -errno;
58 172198d4 Aneesh Kumar K.V
            }
59 172198d4 Aneesh Kumar K.V
        });
60 532decb7 Aneesh Kumar K.V
    v9fs_path_unlock(s);
61 172198d4 Aneesh Kumar K.V
    return err;
62 172198d4 Aneesh Kumar K.V
}
63 03feb1e1 Aneesh Kumar K.V
64 cc720ddb Aneesh Kumar K.V
int v9fs_co_fstat(V9fsPDU *pdu, V9fsFidState *fidp, struct stat *stbuf)
65 03feb1e1 Aneesh Kumar K.V
{
66 03feb1e1 Aneesh Kumar K.V
    int err;
67 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
68 03feb1e1 Aneesh Kumar K.V
69 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
70 bccacf6c Aneesh Kumar K.V
        return -EINTR;
71 bccacf6c Aneesh Kumar K.V
    }
72 03feb1e1 Aneesh Kumar K.V
    v9fs_co_run_in_worker(
73 03feb1e1 Aneesh Kumar K.V
        {
74 8b888272 Aneesh Kumar K.V
            err = s->ops->fstat(&s->ctx, fidp->fid_type, &fidp->fs, stbuf);
75 03feb1e1 Aneesh Kumar K.V
            if (err < 0) {
76 03feb1e1 Aneesh Kumar K.V
                err = -errno;
77 03feb1e1 Aneesh Kumar K.V
            }
78 03feb1e1 Aneesh Kumar K.V
        });
79 03feb1e1 Aneesh Kumar K.V
    return err;
80 03feb1e1 Aneesh Kumar K.V
}
81 f6b7f0ab Aneesh Kumar K.V
82 bccacf6c Aneesh Kumar K.V
int v9fs_co_open(V9fsPDU *pdu, V9fsFidState *fidp, int flags)
83 f6b7f0ab Aneesh Kumar K.V
{
84 f6b7f0ab Aneesh Kumar K.V
    int err;
85 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
86 f6b7f0ab Aneesh Kumar K.V
87 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
88 bccacf6c Aneesh Kumar K.V
        return -EINTR;
89 bccacf6c Aneesh Kumar K.V
    }
90 532decb7 Aneesh Kumar K.V
    v9fs_path_read_lock(s);
91 f6b7f0ab Aneesh Kumar K.V
    v9fs_co_run_in_worker(
92 f6b7f0ab Aneesh Kumar K.V
        {
93 cc720ddb Aneesh Kumar K.V
            err = s->ops->open(&s->ctx, &fidp->path, flags, &fidp->fs);
94 cc720ddb Aneesh Kumar K.V
            if (err == -1) {
95 f6b7f0ab Aneesh Kumar K.V
                err = -errno;
96 f6b7f0ab Aneesh Kumar K.V
            } else {
97 f6b7f0ab Aneesh Kumar K.V
                err = 0;
98 f6b7f0ab Aneesh Kumar K.V
            }
99 f6b7f0ab Aneesh Kumar K.V
        });
100 532decb7 Aneesh Kumar K.V
    v9fs_path_unlock(s);
101 7a462745 Aneesh Kumar K.V
    if (!err) {
102 7a462745 Aneesh Kumar K.V
        total_open_fd++;
103 7a462745 Aneesh Kumar K.V
        if (total_open_fd > open_fd_hw) {
104 bccacf6c Aneesh Kumar K.V
            v9fs_reclaim_fd(pdu);
105 7a462745 Aneesh Kumar K.V
        }
106 7a462745 Aneesh Kumar K.V
    }
107 f6b7f0ab Aneesh Kumar K.V
    return err;
108 f6b7f0ab Aneesh Kumar K.V
}
109 e4de4232 Venkateswararao Jujjuri
110 bccacf6c Aneesh Kumar K.V
int v9fs_co_open2(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, gid_t gid,
111 02cb7f3a Aneesh Kumar K.V
                  int flags, int mode, struct stat *stbuf)
112 e4de4232 Venkateswararao Jujjuri
{
113 e4de4232 Venkateswararao Jujjuri
    int err;
114 e4de4232 Venkateswararao Jujjuri
    FsCred cred;
115 2289be19 Aneesh Kumar K.V
    V9fsPath path;
116 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
117 2289be19 Aneesh Kumar K.V
118 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
119 bccacf6c Aneesh Kumar K.V
        return -EINTR;
120 bccacf6c Aneesh Kumar K.V
    }
121 e4de4232 Venkateswararao Jujjuri
    cred_init(&cred);
122 e4de4232 Venkateswararao Jujjuri
    cred.fc_mode = mode & 07777;
123 e4de4232 Venkateswararao Jujjuri
    cred.fc_uid = fidp->uid;
124 e4de4232 Venkateswararao Jujjuri
    cred.fc_gid = gid;
125 02cb7f3a Aneesh Kumar K.V
    /*
126 02cb7f3a Aneesh Kumar K.V
     * Hold the directory fid lock so that directory path name
127 02cb7f3a Aneesh Kumar K.V
     * don't change. Read lock is fine because this fid cannot
128 02cb7f3a Aneesh Kumar K.V
     * be used by any other operation.
129 02cb7f3a Aneesh Kumar K.V
     */
130 532decb7 Aneesh Kumar K.V
    v9fs_path_read_lock(s);
131 e4de4232 Venkateswararao Jujjuri
    v9fs_co_run_in_worker(
132 e4de4232 Venkateswararao Jujjuri
        {
133 cc720ddb Aneesh Kumar K.V
            err = s->ops->open2(&s->ctx, &fidp->path,
134 cc720ddb Aneesh Kumar K.V
                                name->data, flags, &cred, &fidp->fs);
135 cc720ddb Aneesh Kumar K.V
            if (err < 0) {
136 e4de4232 Venkateswararao Jujjuri
                err = -errno;
137 02cb7f3a Aneesh Kumar K.V
            } else {
138 2289be19 Aneesh Kumar K.V
                v9fs_path_init(&path);
139 2289be19 Aneesh Kumar K.V
                err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
140 2289be19 Aneesh Kumar K.V
                if (!err) {
141 2289be19 Aneesh Kumar K.V
                    err = s->ops->lstat(&s->ctx, &path, stbuf);
142 2289be19 Aneesh Kumar K.V
                    if (err < 0) {
143 2289be19 Aneesh Kumar K.V
                        err = -errno;
144 cc720ddb Aneesh Kumar K.V
                        s->ops->close(&s->ctx, &fidp->fs);
145 2289be19 Aneesh Kumar K.V
                    } else {
146 2289be19 Aneesh Kumar K.V
                        v9fs_path_copy(&fidp->path, &path);
147 2289be19 Aneesh Kumar K.V
                    }
148 02cb7f3a Aneesh Kumar K.V
                } else {
149 cc720ddb Aneesh Kumar K.V
                    s->ops->close(&s->ctx, &fidp->fs);
150 02cb7f3a Aneesh Kumar K.V
                }
151 2289be19 Aneesh Kumar K.V
                v9fs_path_free(&path);
152 e4de4232 Venkateswararao Jujjuri
            }
153 e4de4232 Venkateswararao Jujjuri
        });
154 532decb7 Aneesh Kumar K.V
    v9fs_path_unlock(s);
155 7a462745 Aneesh Kumar K.V
    if (!err) {
156 7a462745 Aneesh Kumar K.V
        total_open_fd++;
157 7a462745 Aneesh Kumar K.V
        if (total_open_fd > open_fd_hw) {
158 bccacf6c Aneesh Kumar K.V
            v9fs_reclaim_fd(pdu);
159 7a462745 Aneesh Kumar K.V
        }
160 7a462745 Aneesh Kumar K.V
    }
161 e4de4232 Venkateswararao Jujjuri
    return err;
162 e4de4232 Venkateswararao Jujjuri
}
163 bed4352c Aneesh Kumar K.V
164 cc720ddb Aneesh Kumar K.V
int v9fs_co_close(V9fsPDU *pdu, V9fsFidOpenState *fs)
165 bed4352c Aneesh Kumar K.V
{
166 bed4352c Aneesh Kumar K.V
    int err;
167 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
168 bed4352c Aneesh Kumar K.V
169 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
170 bccacf6c Aneesh Kumar K.V
        return -EINTR;
171 bccacf6c Aneesh Kumar K.V
    }
172 bed4352c Aneesh Kumar K.V
    v9fs_co_run_in_worker(
173 bed4352c Aneesh Kumar K.V
        {
174 cc720ddb Aneesh Kumar K.V
            err = s->ops->close(&s->ctx, fs);
175 bed4352c Aneesh Kumar K.V
            if (err < 0) {
176 bed4352c Aneesh Kumar K.V
                err = -errno;
177 bed4352c Aneesh Kumar K.V
            }
178 bed4352c Aneesh Kumar K.V
        });
179 7a462745 Aneesh Kumar K.V
    if (!err) {
180 7a462745 Aneesh Kumar K.V
        total_open_fd--;
181 7a462745 Aneesh Kumar K.V
    }
182 bed4352c Aneesh Kumar K.V
    return err;
183 bed4352c Aneesh Kumar K.V
}
184 4743d1f5 Aneesh Kumar K.V
185 bccacf6c Aneesh Kumar K.V
int v9fs_co_fsync(V9fsPDU *pdu, V9fsFidState *fidp, int datasync)
186 4743d1f5 Aneesh Kumar K.V
{
187 cc720ddb Aneesh Kumar K.V
    int err;
188 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
189 4743d1f5 Aneesh Kumar K.V
190 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
191 bccacf6c Aneesh Kumar K.V
        return -EINTR;
192 bccacf6c Aneesh Kumar K.V
    }
193 4743d1f5 Aneesh Kumar K.V
    v9fs_co_run_in_worker(
194 4743d1f5 Aneesh Kumar K.V
        {
195 8b888272 Aneesh Kumar K.V
            err = s->ops->fsync(&s->ctx, fidp->fid_type, &fidp->fs, datasync);
196 4743d1f5 Aneesh Kumar K.V
            if (err < 0) {
197 4743d1f5 Aneesh Kumar K.V
                err = -errno;
198 4743d1f5 Aneesh Kumar K.V
            }
199 4743d1f5 Aneesh Kumar K.V
        });
200 4743d1f5 Aneesh Kumar K.V
    return err;
201 4743d1f5 Aneesh Kumar K.V
}
202 c6c069b0 Venkateswararao Jujjuri
203 bccacf6c Aneesh Kumar K.V
int v9fs_co_link(V9fsPDU *pdu, V9fsFidState *oldfid,
204 2289be19 Aneesh Kumar K.V
                 V9fsFidState *newdirfid, V9fsString *name)
205 c6c069b0 Venkateswararao Jujjuri
{
206 c6c069b0 Venkateswararao Jujjuri
    int err;
207 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
208 c6c069b0 Venkateswararao Jujjuri
209 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
210 bccacf6c Aneesh Kumar K.V
        return -EINTR;
211 bccacf6c Aneesh Kumar K.V
    }
212 532decb7 Aneesh Kumar K.V
    v9fs_path_read_lock(s);
213 c6c069b0 Venkateswararao Jujjuri
    v9fs_co_run_in_worker(
214 c6c069b0 Venkateswararao Jujjuri
        {
215 2289be19 Aneesh Kumar K.V
            err = s->ops->link(&s->ctx, &oldfid->path,
216 2289be19 Aneesh Kumar K.V
                               &newdirfid->path, name->data);
217 c6c069b0 Venkateswararao Jujjuri
            if (err < 0) {
218 c6c069b0 Venkateswararao Jujjuri
                err = -errno;
219 c6c069b0 Venkateswararao Jujjuri
            }
220 c6c069b0 Venkateswararao Jujjuri
        });
221 532decb7 Aneesh Kumar K.V
    v9fs_path_unlock(s);
222 c6c069b0 Venkateswararao Jujjuri
    return err;
223 c6c069b0 Venkateswararao Jujjuri
}
224 f6b3c976 Aneesh Kumar K.V
225 bccacf6c Aneesh Kumar K.V
int v9fs_co_pwritev(V9fsPDU *pdu, V9fsFidState *fidp,
226 f6b3c976 Aneesh Kumar K.V
                    struct iovec *iov, int iovcnt, int64_t offset)
227 f6b3c976 Aneesh Kumar K.V
{
228 cc720ddb Aneesh Kumar K.V
    int err;
229 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
230 f6b3c976 Aneesh Kumar K.V
231 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
232 bccacf6c Aneesh Kumar K.V
        return -EINTR;
233 bccacf6c Aneesh Kumar K.V
    }
234 f6b3c976 Aneesh Kumar K.V
    v9fs_co_run_in_worker(
235 f6b3c976 Aneesh Kumar K.V
        {
236 cc720ddb Aneesh Kumar K.V
            err = s->ops->pwritev(&s->ctx, &fidp->fs, iov, iovcnt, offset);
237 f6b3c976 Aneesh Kumar K.V
            if (err < 0) {
238 f6b3c976 Aneesh Kumar K.V
                err = -errno;
239 f6b3c976 Aneesh Kumar K.V
            }
240 f6b3c976 Aneesh Kumar K.V
        });
241 f6b3c976 Aneesh Kumar K.V
    return err;
242 f6b3c976 Aneesh Kumar K.V
}
243 7eafdcc9 Aneesh Kumar K.V
244 bccacf6c Aneesh Kumar K.V
int v9fs_co_preadv(V9fsPDU *pdu, V9fsFidState *fidp,
245 7eafdcc9 Aneesh Kumar K.V
                   struct iovec *iov, int iovcnt, int64_t offset)
246 7eafdcc9 Aneesh Kumar K.V
{
247 cc720ddb Aneesh Kumar K.V
    int err;
248 bccacf6c Aneesh Kumar K.V
    V9fsState *s = pdu->s;
249 7eafdcc9 Aneesh Kumar K.V
250 bccacf6c Aneesh Kumar K.V
    if (v9fs_request_cancelled(pdu)) {
251 bccacf6c Aneesh Kumar K.V
        return -EINTR;
252 bccacf6c Aneesh Kumar K.V
    }
253 7eafdcc9 Aneesh Kumar K.V
    v9fs_co_run_in_worker(
254 7eafdcc9 Aneesh Kumar K.V
        {
255 cc720ddb Aneesh Kumar K.V
            err = s->ops->preadv(&s->ctx, &fidp->fs, iov, iovcnt, offset);
256 7eafdcc9 Aneesh Kumar K.V
            if (err < 0) {
257 7eafdcc9 Aneesh Kumar K.V
                err = -errno;
258 7eafdcc9 Aneesh Kumar K.V
            }
259 7eafdcc9 Aneesh Kumar K.V
        });
260 7eafdcc9 Aneesh Kumar K.V
    return err;
261 7eafdcc9 Aneesh Kumar K.V
}