Revision cc720ddb hw/9pfs/virtio-9p-handle.c
b/hw/9pfs/virtio-9p-handle.c | ||
---|---|---|
133 | 133 |
return ret; |
134 | 134 |
} |
135 | 135 |
|
136 |
static int handle_close(FsContext *ctx, int fd)
|
|
136 |
static int handle_close(FsContext *ctx, V9fsFidOpenState *fs)
|
|
137 | 137 |
{ |
138 |
return close(fd); |
|
138 |
return close(fs->fd);
|
|
139 | 139 |
} |
140 | 140 |
|
141 |
static int handle_closedir(FsContext *ctx, DIR *dir)
|
|
141 |
static int handle_closedir(FsContext *ctx, V9fsFidOpenState *fs)
|
|
142 | 142 |
{ |
143 |
return closedir(dir); |
|
143 |
return closedir(fs->dir);
|
|
144 | 144 |
} |
145 | 145 |
|
146 |
static int handle_open(FsContext *ctx, V9fsPath *fs_path, int flags) |
|
146 |
static int handle_open(FsContext *ctx, V9fsPath *fs_path, |
|
147 |
int flags, V9fsFidOpenState *fs) |
|
147 | 148 |
{ |
148 | 149 |
struct handle_data *data = (struct handle_data *)ctx->private; |
149 | 150 |
|
150 |
return open_by_handle(data->mountfd, fs_path->data, flags); |
|
151 |
fs->fd = open_by_handle(data->mountfd, fs_path->data, flags); |
|
152 |
return fs->fd; |
|
151 | 153 |
} |
152 | 154 |
|
153 |
static DIR *handle_opendir(FsContext *ctx, V9fsPath *fs_path) |
|
155 |
static int handle_opendir(FsContext *ctx, |
|
156 |
V9fsPath *fs_path, V9fsFidOpenState *fs) |
|
154 | 157 |
{ |
155 |
int fd;
|
|
156 |
fd = handle_open(ctx, fs_path, O_DIRECTORY);
|
|
157 |
if (fd < 0) {
|
|
158 |
return NULL;
|
|
158 |
int ret;
|
|
159 |
ret = handle_open(ctx, fs_path, O_DIRECTORY, fs);
|
|
160 |
if (ret < 0) {
|
|
161 |
return -1;
|
|
159 | 162 |
} |
160 |
return fdopendir(fd); |
|
163 |
fs->dir = fdopendir(ret); |
|
164 |
if (!fs->dir) { |
|
165 |
return -1; |
|
166 |
} |
|
167 |
return 0; |
|
161 | 168 |
} |
162 | 169 |
|
163 |
static void handle_rewinddir(FsContext *ctx, DIR *dir)
|
|
170 |
static void handle_rewinddir(FsContext *ctx, V9fsFidOpenState *fs)
|
|
164 | 171 |
{ |
165 |
return rewinddir(dir); |
|
172 |
return rewinddir(fs->dir);
|
|
166 | 173 |
} |
167 | 174 |
|
168 |
static off_t handle_telldir(FsContext *ctx, DIR *dir)
|
|
175 |
static off_t handle_telldir(FsContext *ctx, V9fsFidOpenState *fs)
|
|
169 | 176 |
{ |
170 |
return telldir(dir); |
|
177 |
return telldir(fs->dir);
|
|
171 | 178 |
} |
172 | 179 |
|
173 |
static int handle_readdir_r(FsContext *ctx, DIR *dir, struct dirent *entry, |
|
180 |
static int handle_readdir_r(FsContext *ctx, V9fsFidOpenState *fs, |
|
181 |
struct dirent *entry, |
|
174 | 182 |
struct dirent **result) |
175 | 183 |
{ |
176 |
return readdir_r(dir, entry, result); |
|
184 |
return readdir_r(fs->dir, entry, result);
|
|
177 | 185 |
} |
178 | 186 |
|
179 |
static void handle_seekdir(FsContext *ctx, DIR *dir, off_t off)
|
|
187 |
static void handle_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
|
|
180 | 188 |
{ |
181 |
return seekdir(dir, off); |
|
189 |
return seekdir(fs->dir, off);
|
|
182 | 190 |
} |
183 | 191 |
|
184 |
static ssize_t handle_preadv(FsContext *ctx, int fd, const struct iovec *iov, |
|
192 |
static ssize_t handle_preadv(FsContext *ctx, V9fsFidOpenState *fs, |
|
193 |
const struct iovec *iov, |
|
185 | 194 |
int iovcnt, off_t offset) |
186 | 195 |
{ |
187 | 196 |
#ifdef CONFIG_PREADV |
188 |
return preadv(fd, iov, iovcnt, offset); |
|
197 |
return preadv(fs->fd, iov, iovcnt, offset);
|
|
189 | 198 |
#else |
190 |
int err = lseek(fd, offset, SEEK_SET); |
|
199 |
int err = lseek(fs->fd, offset, SEEK_SET);
|
|
191 | 200 |
if (err == -1) { |
192 | 201 |
return err; |
193 | 202 |
} else { |
194 |
return readv(fd, iov, iovcnt); |
|
203 |
return readv(fs->fd, iov, iovcnt);
|
|
195 | 204 |
} |
196 | 205 |
#endif |
197 | 206 |
} |
198 | 207 |
|
199 |
static ssize_t handle_pwritev(FsContext *ctx, int fd, const struct iovec *iov, |
|
208 |
static ssize_t handle_pwritev(FsContext *ctx, V9fsFidOpenState *fs, |
|
209 |
const struct iovec *iov, |
|
200 | 210 |
int iovcnt, off_t offset) |
201 | 211 |
{ |
202 | 212 |
ssize_t ret; |
203 | 213 |
#ifdef CONFIG_PREADV |
204 |
ret = pwritev(fd, iov, iovcnt, offset); |
|
214 |
ret = pwritev(fs->fd, iov, iovcnt, offset);
|
|
205 | 215 |
#else |
206 |
int err = lseek(fd, offset, SEEK_SET); |
|
216 |
int err = lseek(fs->fd, offset, SEEK_SET);
|
|
207 | 217 |
if (err == -1) { |
208 | 218 |
return err; |
209 | 219 |
} else { |
210 |
ret = writev(fd, iov, iovcnt); |
|
220 |
ret = writev(fs->fd, iov, iovcnt);
|
|
211 | 221 |
} |
212 | 222 |
#endif |
213 | 223 |
#ifdef CONFIG_SYNC_FILE_RANGE |
... | ... | |
217 | 227 |
* We want to ensure that we don't leave dirty pages in the cache |
218 | 228 |
* after write when writeout=immediate is sepcified. |
219 | 229 |
*/ |
220 |
sync_file_range(fd, offset, ret, |
|
230 |
sync_file_range(fs->fd, offset, ret,
|
|
221 | 231 |
SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE); |
222 | 232 |
} |
223 | 233 |
#endif |
... | ... | |
274 | 284 |
return ret; |
275 | 285 |
} |
276 | 286 |
|
277 |
static int handle_fstat(FsContext *fs_ctx, int fd, struct stat *stbuf) |
|
287 |
static int handle_fstat(FsContext *fs_ctx, V9fsFidOpenState *fs, |
|
288 |
struct stat *stbuf) |
|
278 | 289 |
{ |
279 |
return fstat(fd, stbuf); |
|
290 |
return fstat(fs->fd, stbuf);
|
|
280 | 291 |
} |
281 | 292 |
|
282 | 293 |
static int handle_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, |
283 |
int flags, FsCred *credp)
|
|
294 |
int flags, FsCred *credp, V9fsFidOpenState *fs)
|
|
284 | 295 |
{ |
285 | 296 |
int ret; |
286 | 297 |
int dirfd, fd; |
... | ... | |
296 | 307 |
if (ret < 0) { |
297 | 308 |
close(fd); |
298 | 309 |
fd = ret; |
310 |
} else { |
|
311 |
fs->fd = fd; |
|
299 | 312 |
} |
300 | 313 |
} |
301 | 314 |
close(dirfd); |
... | ... | |
411 | 424 |
return -1; |
412 | 425 |
} |
413 | 426 |
|
414 |
static int handle_fsync(FsContext *ctx, int fd, int datasync)
|
|
427 |
static int handle_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync)
|
|
415 | 428 |
{ |
416 | 429 |
if (datasync) { |
417 |
return qemu_fdatasync(fd); |
|
430 |
return qemu_fdatasync(fs->fd);
|
|
418 | 431 |
} else { |
419 |
return fsync(fd); |
|
432 |
return fsync(fs->fd);
|
|
420 | 433 |
} |
421 | 434 |
} |
422 | 435 |
|
... | ... | |
575 | 588 |
static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path, |
576 | 589 |
mode_t st_mode, uint64_t *st_gen) |
577 | 590 |
{ |
578 |
int err, fd; |
|
591 |
int err; |
|
592 |
V9fsFidOpenState fid_open; |
|
579 | 593 |
|
580 | 594 |
/* |
581 | 595 |
* Do not try to open special files like device nodes, fifos etc |
... | ... | |
584 | 598 |
if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) { |
585 | 599 |
return 0; |
586 | 600 |
} |
587 |
fd = handle_open(ctx, path, O_RDONLY);
|
|
588 |
if (fd < 0) {
|
|
589 |
return fd;
|
|
601 |
err = handle_open(ctx, path, O_RDONLY, &fid_open);
|
|
602 |
if (err < 0) {
|
|
603 |
return err;
|
|
590 | 604 |
} |
591 |
err = ioctl(fd, FS_IOC_GETVERSION, st_gen); |
|
592 |
handle_close(ctx, fd);
|
|
605 |
err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
|
|
606 |
handle_close(ctx, &fid_open);
|
|
593 | 607 |
return err; |
594 | 608 |
} |
595 | 609 |
|
Also available in: Unified diff