Venkateswararao Jujjuri (JV) | 86e42d7 | 2011-08-08 23:33:48 +0530 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Virtio 9p backend |
| 4 | * |
| 5 | * Copyright IBM, Corp. 2011 |
| 6 | * |
| 7 | * Authors: |
| 8 | * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> |
| 9 | * |
| 10 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 11 | * the COPYING file in the top-level directory. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include "fsdev/qemu-fsdev.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 16 | #include "qemu/thread.h" |
Daniel P. Berrange | 10817bf | 2015-09-01 14:48:02 +0100 | [diff] [blame] | 17 | #include "qemu/coroutine.h" |
Venkateswararao Jujjuri (JV) | 86e42d7 | 2011-08-08 23:33:48 +0530 | [diff] [blame] | 18 | #include "virtio-9p-coth.h" |
| 19 | |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 20 | static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf) |
| 21 | { |
| 22 | ssize_t len, maxlen = PATH_MAX; |
| 23 | |
| 24 | buf->data = g_malloc(PATH_MAX); |
| 25 | for(;;) { |
| 26 | len = s->ops->readlink(&s->ctx, path, buf->data, maxlen); |
| 27 | if (len < 0) { |
| 28 | g_free(buf->data); |
| 29 | buf->data = NULL; |
| 30 | buf->size = 0; |
| 31 | break; |
| 32 | } else if (len == maxlen) { |
| 33 | /* |
| 34 | * We dodn't have space to put the NULL or we have more |
| 35 | * to read. Increase the size and try again |
| 36 | */ |
| 37 | maxlen *= 2; |
| 38 | g_free(buf->data); |
| 39 | buf->data = g_malloc(maxlen); |
| 40 | continue; |
| 41 | } |
| 42 | /* |
| 43 | * Null terminate the readlink output |
| 44 | */ |
| 45 | buf->data[len] = '\0'; |
| 46 | buf->size = len; |
| 47 | break; |
| 48 | } |
| 49 | return len; |
| 50 | } |
| 51 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 52 | int v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf) |
Venkateswararao Jujjuri (JV) | 86e42d7 | 2011-08-08 23:33:48 +0530 | [diff] [blame] | 53 | { |
| 54 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 55 | V9fsState *s = pdu->s; |
Venkateswararao Jujjuri (JV) | 86e42d7 | 2011-08-08 23:33:48 +0530 | [diff] [blame] | 56 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 57 | if (v9fs_request_cancelled(pdu)) { |
| 58 | return -EINTR; |
| 59 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 60 | v9fs_path_read_lock(s); |
Venkateswararao Jujjuri (JV) | 86e42d7 | 2011-08-08 23:33:48 +0530 | [diff] [blame] | 61 | v9fs_co_run_in_worker( |
| 62 | { |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 63 | err = __readlink(s, path, buf); |
| 64 | if (err < 0) { |
Venkateswararao Jujjuri (JV) | 86e42d7 | 2011-08-08 23:33:48 +0530 | [diff] [blame] | 65 | err = -errno; |
| 66 | } |
| 67 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 68 | v9fs_path_unlock(s); |
Venkateswararao Jujjuri (JV) | 86e42d7 | 2011-08-08 23:33:48 +0530 | [diff] [blame] | 69 | return err; |
| 70 | } |
Aneesh Kumar K.V | 94840ff | 2011-05-18 16:03:49 -0700 | [diff] [blame] | 71 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 72 | int v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path, struct statfs *stbuf) |
Aneesh Kumar K.V | 94840ff | 2011-05-18 16:03:49 -0700 | [diff] [blame] | 73 | { |
| 74 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 75 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 94840ff | 2011-05-18 16:03:49 -0700 | [diff] [blame] | 76 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 77 | if (v9fs_request_cancelled(pdu)) { |
| 78 | return -EINTR; |
| 79 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 80 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | 94840ff | 2011-05-18 16:03:49 -0700 | [diff] [blame] | 81 | v9fs_co_run_in_worker( |
| 82 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 83 | err = s->ops->statfs(&s->ctx, path, stbuf); |
Aneesh Kumar K.V | 94840ff | 2011-05-18 16:03:49 -0700 | [diff] [blame] | 84 | if (err < 0) { |
| 85 | err = -errno; |
| 86 | } |
| 87 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 88 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 94840ff | 2011-05-18 16:03:49 -0700 | [diff] [blame] | 89 | return err; |
| 90 | } |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 91 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 92 | int v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode) |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 93 | { |
| 94 | int err; |
| 95 | FsCred cred; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 96 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 97 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 98 | if (v9fs_request_cancelled(pdu)) { |
| 99 | return -EINTR; |
| 100 | } |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 101 | cred_init(&cred); |
| 102 | cred.fc_mode = mode; |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 103 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 104 | v9fs_co_run_in_worker( |
| 105 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 106 | err = s->ops->chmod(&s->ctx, path, &cred); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 107 | if (err < 0) { |
| 108 | err = -errno; |
| 109 | } |
| 110 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 111 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 112 | return err; |
| 113 | } |
| 114 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 115 | int v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path, |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 116 | struct timespec times[2]) |
| 117 | { |
| 118 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 119 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 120 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 121 | if (v9fs_request_cancelled(pdu)) { |
| 122 | return -EINTR; |
| 123 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 124 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 125 | v9fs_co_run_in_worker( |
| 126 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 127 | err = s->ops->utimensat(&s->ctx, path, times); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 128 | if (err < 0) { |
| 129 | err = -errno; |
| 130 | } |
| 131 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 132 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 133 | return err; |
| 134 | } |
| 135 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 136 | int v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid, gid_t gid) |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 137 | { |
| 138 | int err; |
| 139 | FsCred cred; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 140 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 141 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 142 | if (v9fs_request_cancelled(pdu)) { |
| 143 | return -EINTR; |
| 144 | } |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 145 | cred_init(&cred); |
| 146 | cred.fc_uid = uid; |
| 147 | cred.fc_gid = gid; |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 148 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 149 | v9fs_co_run_in_worker( |
| 150 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 151 | err = s->ops->chown(&s->ctx, path, &cred); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 152 | if (err < 0) { |
| 153 | err = -errno; |
| 154 | } |
| 155 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 156 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 157 | return err; |
| 158 | } |
| 159 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 160 | int v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size) |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 161 | { |
| 162 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 163 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 164 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 165 | if (v9fs_request_cancelled(pdu)) { |
| 166 | return -EINTR; |
| 167 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 168 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 169 | v9fs_co_run_in_worker( |
| 170 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 171 | err = s->ops->truncate(&s->ctx, path, size); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 172 | if (err < 0) { |
| 173 | err = -errno; |
| 174 | } |
| 175 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 176 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 4011ead | 2011-05-18 16:04:58 -0700 | [diff] [blame] | 177 | return err; |
| 178 | } |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 179 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 180 | int v9fs_co_mknod(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, uid_t uid, |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 181 | gid_t gid, dev_t dev, mode_t mode, struct stat *stbuf) |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 182 | { |
| 183 | int err; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 184 | V9fsPath path; |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 185 | FsCred cred; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 186 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 187 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 188 | if (v9fs_request_cancelled(pdu)) { |
| 189 | return -EINTR; |
| 190 | } |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 191 | cred_init(&cred); |
| 192 | cred.fc_uid = uid; |
| 193 | cred.fc_gid = gid; |
| 194 | cred.fc_mode = mode; |
| 195 | cred.fc_rdev = dev; |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 196 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 197 | v9fs_co_run_in_worker( |
| 198 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 199 | err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred); |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 200 | if (err < 0) { |
| 201 | err = -errno; |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 202 | } else { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 203 | v9fs_path_init(&path); |
| 204 | err = v9fs_name_to_path(s, &fidp->path, name->data, &path); |
| 205 | if (!err) { |
| 206 | err = s->ops->lstat(&s->ctx, &path, stbuf); |
| 207 | if (err < 0) { |
| 208 | err = -errno; |
| 209 | } |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 210 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 211 | v9fs_path_free(&path); |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 212 | } |
| 213 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 214 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 00ace8c | 2011-05-18 16:06:38 -0700 | [diff] [blame] | 215 | return err; |
| 216 | } |
Venkateswararao Jujjuri | b4b1537 | 2011-08-08 23:48:29 +0530 | [diff] [blame] | 217 | |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 218 | /* Only works with path name based fid */ |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 219 | int v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path) |
Venkateswararao Jujjuri | b4b1537 | 2011-08-08 23:48:29 +0530 | [diff] [blame] | 220 | { |
| 221 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 222 | V9fsState *s = pdu->s; |
Venkateswararao Jujjuri | b4b1537 | 2011-08-08 23:48:29 +0530 | [diff] [blame] | 223 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 224 | if (v9fs_request_cancelled(pdu)) { |
| 225 | return -EINTR; |
| 226 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 227 | v9fs_path_read_lock(s); |
Venkateswararao Jujjuri | b4b1537 | 2011-08-08 23:48:29 +0530 | [diff] [blame] | 228 | v9fs_co_run_in_worker( |
| 229 | { |
| 230 | err = s->ops->remove(&s->ctx, path->data); |
| 231 | if (err < 0) { |
| 232 | err = -errno; |
| 233 | } |
| 234 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 235 | v9fs_path_unlock(s); |
Venkateswararao Jujjuri | b4b1537 | 2011-08-08 23:48:29 +0530 | [diff] [blame] | 236 | return err; |
| 237 | } |
Aneesh Kumar K.V | 2a487e0 | 2011-05-07 16:09:10 +0530 | [diff] [blame] | 238 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 239 | int v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path, V9fsString *name, int flags) |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 240 | { |
| 241 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 242 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 243 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 244 | if (v9fs_request_cancelled(pdu)) { |
| 245 | return -EINTR; |
| 246 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 247 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 248 | v9fs_co_run_in_worker( |
| 249 | { |
| 250 | err = s->ops->unlinkat(&s->ctx, path, name->data, flags); |
| 251 | if (err < 0) { |
| 252 | err = -errno; |
| 253 | } |
| 254 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 255 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 256 | return err; |
| 257 | } |
| 258 | |
| 259 | /* Only work with path name based fid */ |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 260 | int v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath, V9fsPath *newpath) |
Aneesh Kumar K.V | 2a487e0 | 2011-05-07 16:09:10 +0530 | [diff] [blame] | 261 | { |
| 262 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 263 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 2a487e0 | 2011-05-07 16:09:10 +0530 | [diff] [blame] | 264 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 265 | if (v9fs_request_cancelled(pdu)) { |
| 266 | return -EINTR; |
| 267 | } |
Aneesh Kumar K.V | 2a487e0 | 2011-05-07 16:09:10 +0530 | [diff] [blame] | 268 | v9fs_co_run_in_worker( |
| 269 | { |
| 270 | err = s->ops->rename(&s->ctx, oldpath->data, newpath->data); |
| 271 | if (err < 0) { |
| 272 | err = -errno; |
| 273 | } |
| 274 | }); |
| 275 | return err; |
| 276 | } |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 277 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 278 | int v9fs_co_renameat(V9fsPDU *pdu, V9fsPath *olddirpath, V9fsString *oldname, |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 279 | V9fsPath *newdirpath, V9fsString *newname) |
| 280 | { |
| 281 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 282 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 283 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 284 | if (v9fs_request_cancelled(pdu)) { |
| 285 | return -EINTR; |
| 286 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 287 | v9fs_co_run_in_worker( |
| 288 | { |
| 289 | err = s->ops->renameat(&s->ctx, olddirpath, oldname->data, |
| 290 | newdirpath, newname->data); |
| 291 | if (err < 0) { |
| 292 | err = -errno; |
| 293 | } |
| 294 | }); |
| 295 | return err; |
| 296 | } |
| 297 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 298 | int v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp, V9fsString *name, |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 299 | const char *oldpath, gid_t gid, struct stat *stbuf) |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 300 | { |
| 301 | int err; |
| 302 | FsCred cred; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 303 | V9fsPath path; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 304 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 305 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 306 | if (v9fs_request_cancelled(pdu)) { |
| 307 | return -EINTR; |
| 308 | } |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 309 | cred_init(&cred); |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 310 | cred.fc_uid = dfidp->uid; |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 311 | cred.fc_gid = gid; |
| 312 | cred.fc_mode = 0777; |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 313 | v9fs_path_read_lock(s); |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 314 | v9fs_co_run_in_worker( |
| 315 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 316 | err = s->ops->symlink(&s->ctx, oldpath, &dfidp->path, |
| 317 | name->data, &cred); |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 318 | if (err < 0) { |
| 319 | err = -errno; |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 320 | } else { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 321 | v9fs_path_init(&path); |
| 322 | err = v9fs_name_to_path(s, &dfidp->path, name->data, &path); |
| 323 | if (!err) { |
| 324 | err = s->ops->lstat(&s->ctx, &path, stbuf); |
| 325 | if (err < 0) { |
| 326 | err = -errno; |
| 327 | } |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 328 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 329 | v9fs_path_free(&path); |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 330 | } |
| 331 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 332 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 333 | return err; |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | * For path name based fid we don't block. So we can |
| 338 | * directly call the fs driver ops. |
| 339 | */ |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 340 | int v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath, |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 341 | const char *name, V9fsPath *path) |
| 342 | { |
| 343 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 344 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 345 | |
Aneesh Kumar K.V | c98f1d4 | 2011-10-12 20:59:18 +0530 | [diff] [blame] | 346 | if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 347 | err = s->ops->name_to_path(&s->ctx, dirpath, name, path); |
| 348 | if (err < 0) { |
| 349 | err = -errno; |
| 350 | } |
| 351 | } else { |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 352 | if (v9fs_request_cancelled(pdu)) { |
| 353 | return -EINTR; |
| 354 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 355 | v9fs_co_run_in_worker( |
| 356 | { |
| 357 | err = s->ops->name_to_path(&s->ctx, dirpath, name, path); |
| 358 | if (err < 0) { |
| 359 | err = -errno; |
| 360 | } |
| 361 | }); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 362 | } |
Venkateswararao Jujjuri | 02ac7a3 | 2011-08-08 23:58:39 +0530 | [diff] [blame] | 363 | return err; |
| 364 | } |