2 * QEMU Block driver for native access to files on NFS shares
4 * Copyright (c) 2014-2016 Peter Lieven <pl@kamp.de>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
28 #include "qemu-common.h"
29 #include "qemu/config-file.h"
30 #include "qemu/error-report.h"
31 #include "qapi/error.h"
32 #include "block/block_int.h"
36 #include "qemu/cutils.h"
37 #include "sysemu/sysemu.h"
38 #include "qapi/qmp/qdict.h"
39 #include "qapi/qmp/qint.h"
40 #include "qapi/qmp/qstring.h"
41 #include "qapi-visit.h"
42 #include "qapi/qobject-input-visitor.h"
43 #include "qapi/qobject-output-visitor.h"
44 #include <nfsc/libnfs.h>
47 #define QEMU_NFS_MAX_READAHEAD_SIZE 1048576
48 #define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)
49 #define QEMU_NFS_MAX_DEBUG_LEVEL 2
51 typedef struct NFSClient
{
52 struct nfs_context
*context
;
56 AioContext
*aio_context
;
62 int64_t uid
, gid
, tcp_syncnt
, readahead
, pagecache
, debug
;
65 typedef struct NFSRPC
{
75 static int nfs_parse_uri(const char *filename
, QDict
*options
, Error
**errp
)
78 QueryParams
*qp
= NULL
;
81 uri
= uri_parse(filename
);
83 error_setg(errp
, "Invalid URI specified");
86 if (strcmp(uri
->scheme
, "nfs") != 0) {
87 error_setg(errp
, "URI scheme must be 'nfs'");
92 error_setg(errp
, "missing hostname in URI");
97 error_setg(errp
, "missing file path in URI");
101 qp
= query_params_parse(uri
->query
);
103 error_setg(errp
, "could not parse query parameters");
107 qdict_put_str(options
, "server.host", uri
->server
);
108 qdict_put_str(options
, "server.type", "inet");
109 qdict_put_str(options
, "path", uri
->path
);
111 for (i
= 0; i
< qp
->n
; i
++) {
112 unsigned long long val
;
113 if (!qp
->p
[i
].value
) {
114 error_setg(errp
, "Value for NFS parameter expected: %s",
118 if (parse_uint_full(qp
->p
[i
].value
, &val
, 0)) {
119 error_setg(errp
, "Illegal value for NFS parameter: %s",
123 if (!strcmp(qp
->p
[i
].name
, "uid")) {
124 qdict_put_str(options
, "user", qp
->p
[i
].value
);
125 } else if (!strcmp(qp
->p
[i
].name
, "gid")) {
126 qdict_put_str(options
, "group", qp
->p
[i
].value
);
127 } else if (!strcmp(qp
->p
[i
].name
, "tcp-syncnt")) {
128 qdict_put_str(options
, "tcp-syn-count", qp
->p
[i
].value
);
129 } else if (!strcmp(qp
->p
[i
].name
, "readahead")) {
130 qdict_put_str(options
, "readahead-size", qp
->p
[i
].value
);
131 } else if (!strcmp(qp
->p
[i
].name
, "pagecache")) {
132 qdict_put_str(options
, "page-cache-size", qp
->p
[i
].value
);
133 } else if (!strcmp(qp
->p
[i
].name
, "debug")) {
134 qdict_put_str(options
, "debug", qp
->p
[i
].value
);
136 error_setg(errp
, "Unknown NFS parameter name: %s",
144 query_params_free(qp
);
152 static bool nfs_has_filename_options_conflict(QDict
*options
, Error
**errp
)
154 const QDictEntry
*qe
;
156 for (qe
= qdict_first(options
); qe
; qe
= qdict_next(options
, qe
)) {
157 if (!strcmp(qe
->key
, "host") ||
158 !strcmp(qe
->key
, "path") ||
159 !strcmp(qe
->key
, "user") ||
160 !strcmp(qe
->key
, "group") ||
161 !strcmp(qe
->key
, "tcp-syn-count") ||
162 !strcmp(qe
->key
, "readahead-size") ||
163 !strcmp(qe
->key
, "page-cache-size") ||
164 !strcmp(qe
->key
, "debug") ||
165 strstart(qe
->key
, "server.", NULL
))
167 error_setg(errp
, "Option %s cannot be used with a filename",
176 static void nfs_parse_filename(const char *filename
, QDict
*options
,
179 if (nfs_has_filename_options_conflict(options
, errp
)) {
183 nfs_parse_uri(filename
, options
, errp
);
186 static void nfs_process_read(void *arg
);
187 static void nfs_process_write(void *arg
);
189 /* Called with QemuMutex held. */
190 static void nfs_set_events(NFSClient
*client
)
192 int ev
= nfs_which_events(client
->context
);
193 if (ev
!= client
->events
) {
194 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
196 (ev
& POLLIN
) ? nfs_process_read
: NULL
,
197 (ev
& POLLOUT
) ? nfs_process_write
: NULL
,
204 static void nfs_process_read(void *arg
)
206 NFSClient
*client
= arg
;
208 qemu_mutex_lock(&client
->mutex
);
209 nfs_service(client
->context
, POLLIN
);
210 nfs_set_events(client
);
211 qemu_mutex_unlock(&client
->mutex
);
214 static void nfs_process_write(void *arg
)
216 NFSClient
*client
= arg
;
218 qemu_mutex_lock(&client
->mutex
);
219 nfs_service(client
->context
, POLLOUT
);
220 nfs_set_events(client
);
221 qemu_mutex_unlock(&client
->mutex
);
224 static void nfs_co_init_task(BlockDriverState
*bs
, NFSRPC
*task
)
227 .co
= qemu_coroutine_self(),
229 .client
= bs
->opaque
,
233 static void nfs_co_generic_bh_cb(void *opaque
)
235 NFSRPC
*task
= opaque
;
238 aio_co_wake(task
->co
);
241 /* Called (via nfs_service) with QemuMutex held. */
243 nfs_co_generic_cb(int ret
, struct nfs_context
*nfs
, void *data
,
246 NFSRPC
*task
= private_data
;
249 if (task
->ret
> 0 && task
->iov
) {
250 if (task
->ret
<= task
->iov
->size
) {
251 qemu_iovec_from_buf(task
->iov
, 0, data
, task
->ret
);
257 error_report("NFS Error: %s", nfs_get_error(nfs
));
259 aio_bh_schedule_oneshot(task
->client
->aio_context
,
260 nfs_co_generic_bh_cb
, task
);
263 static int coroutine_fn
nfs_co_preadv(BlockDriverState
*bs
, uint64_t offset
,
264 uint64_t bytes
, QEMUIOVector
*iov
,
267 NFSClient
*client
= bs
->opaque
;
270 nfs_co_init_task(bs
, &task
);
273 qemu_mutex_lock(&client
->mutex
);
274 if (nfs_pread_async(client
->context
, client
->fh
,
275 offset
, bytes
, nfs_co_generic_cb
, &task
) != 0) {
276 qemu_mutex_unlock(&client
->mutex
);
280 nfs_set_events(client
);
281 qemu_mutex_unlock(&client
->mutex
);
282 while (!task
.complete
) {
283 qemu_coroutine_yield();
290 /* zero pad short reads */
291 if (task
.ret
< iov
->size
) {
292 qemu_iovec_memset(iov
, task
.ret
, 0, iov
->size
- task
.ret
);
298 static int coroutine_fn
nfs_co_pwritev(BlockDriverState
*bs
, uint64_t offset
,
299 uint64_t bytes
, QEMUIOVector
*iov
,
302 NFSClient
*client
= bs
->opaque
;
305 bool my_buffer
= false;
307 nfs_co_init_task(bs
, &task
);
309 if (iov
->niov
!= 1) {
310 buf
= g_try_malloc(bytes
);
311 if (bytes
&& buf
== NULL
) {
314 qemu_iovec_to_buf(iov
, 0, buf
, bytes
);
317 buf
= iov
->iov
[0].iov_base
;
320 qemu_mutex_lock(&client
->mutex
);
321 if (nfs_pwrite_async(client
->context
, client
->fh
,
323 nfs_co_generic_cb
, &task
) != 0) {
324 qemu_mutex_unlock(&client
->mutex
);
331 nfs_set_events(client
);
332 qemu_mutex_unlock(&client
->mutex
);
333 while (!task
.complete
) {
334 qemu_coroutine_yield();
341 if (task
.ret
!= bytes
) {
342 return task
.ret
< 0 ? task
.ret
: -EIO
;
348 static int coroutine_fn
nfs_co_flush(BlockDriverState
*bs
)
350 NFSClient
*client
= bs
->opaque
;
353 nfs_co_init_task(bs
, &task
);
355 qemu_mutex_lock(&client
->mutex
);
356 if (nfs_fsync_async(client
->context
, client
->fh
, nfs_co_generic_cb
,
358 qemu_mutex_unlock(&client
->mutex
);
362 nfs_set_events(client
);
363 qemu_mutex_unlock(&client
->mutex
);
364 while (!task
.complete
) {
365 qemu_coroutine_yield();
371 static QemuOptsList runtime_opts
= {
373 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
377 .type
= QEMU_OPT_STRING
,
378 .help
= "Path of the image on the host",
382 .type
= QEMU_OPT_NUMBER
,
383 .help
= "UID value to use when talking to the server",
387 .type
= QEMU_OPT_NUMBER
,
388 .help
= "GID value to use when talking to the server",
391 .name
= "tcp-syn-count",
392 .type
= QEMU_OPT_NUMBER
,
393 .help
= "Number of SYNs to send during the session establish",
396 .name
= "readahead-size",
397 .type
= QEMU_OPT_NUMBER
,
398 .help
= "Set the readahead size in bytes",
401 .name
= "page-cache-size",
402 .type
= QEMU_OPT_NUMBER
,
403 .help
= "Set the pagecache size in bytes",
407 .type
= QEMU_OPT_NUMBER
,
408 .help
= "Set the NFS debug level (max 2)",
410 { /* end of list */ }
414 static void nfs_detach_aio_context(BlockDriverState
*bs
)
416 NFSClient
*client
= bs
->opaque
;
418 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
419 false, NULL
, NULL
, NULL
, NULL
);
423 static void nfs_attach_aio_context(BlockDriverState
*bs
,
424 AioContext
*new_context
)
426 NFSClient
*client
= bs
->opaque
;
428 client
->aio_context
= new_context
;
429 nfs_set_events(client
);
432 static void nfs_client_close(NFSClient
*client
)
434 if (client
->context
) {
436 nfs_close(client
->context
, client
->fh
);
438 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
439 false, NULL
, NULL
, NULL
, NULL
);
440 nfs_destroy_context(client
->context
);
442 memset(client
, 0, sizeof(NFSClient
));
445 static void nfs_file_close(BlockDriverState
*bs
)
447 NFSClient
*client
= bs
->opaque
;
448 nfs_client_close(client
);
449 qemu_mutex_destroy(&client
->mutex
);
452 static NFSServer
*nfs_config(QDict
*options
, Error
**errp
)
454 NFSServer
*server
= NULL
;
456 QObject
*crumpled_addr
= NULL
;
458 Error
*local_error
= NULL
;
460 qdict_extract_subqdict(options
, &addr
, "server.");
461 if (!qdict_size(addr
)) {
462 error_setg(errp
, "NFS server address missing");
466 crumpled_addr
= qdict_crumple(addr
, errp
);
467 if (!crumpled_addr
) {
472 * Caution: this works only because all scalar members of
473 * NFSServer are QString in @crumpled_addr. The visitor expects
474 * @crumpled_addr to be typed according to the QAPI schema. It
475 * is when @options come from -blockdev or blockdev_add. But when
476 * they come from -drive, they're all QString.
478 iv
= qobject_input_visitor_new(crumpled_addr
);
479 visit_type_NFSServer(iv
, NULL
, &server
, &local_error
);
481 error_propagate(errp
, local_error
);
487 qobject_decref(crumpled_addr
);
493 static int64_t nfs_client_open(NFSClient
*client
, QDict
*options
,
494 int flags
, int open_flags
, Error
**errp
)
497 QemuOpts
*opts
= NULL
;
498 Error
*local_err
= NULL
;
500 char *file
= NULL
, *strp
= NULL
;
502 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
503 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
505 error_propagate(errp
, local_err
);
510 client
->path
= g_strdup(qemu_opt_get(opts
, "path"));
513 error_setg(errp
, "No path was specified");
517 strp
= strrchr(client
->path
, '/');
519 error_setg(errp
, "Invalid URL specified");
522 file
= g_strdup(strp
);
525 /* Pop the config into our state object, Exit if invalid */
526 client
->server
= nfs_config(options
, errp
);
527 if (!client
->server
) {
532 client
->context
= nfs_init_context();
533 if (client
->context
== NULL
) {
534 error_setg(errp
, "Failed to init NFS context");
538 if (qemu_opt_get(opts
, "user")) {
539 client
->uid
= qemu_opt_get_number(opts
, "user", 0);
540 nfs_set_uid(client
->context
, client
->uid
);
543 if (qemu_opt_get(opts
, "group")) {
544 client
->gid
= qemu_opt_get_number(opts
, "group", 0);
545 nfs_set_gid(client
->context
, client
->gid
);
548 if (qemu_opt_get(opts
, "tcp-syn-count")) {
549 client
->tcp_syncnt
= qemu_opt_get_number(opts
, "tcp-syn-count", 0);
550 nfs_set_tcp_syncnt(client
->context
, client
->tcp_syncnt
);
553 #ifdef LIBNFS_FEATURE_READAHEAD
554 if (qemu_opt_get(opts
, "readahead-size")) {
555 if (open_flags
& BDRV_O_NOCACHE
) {
556 error_setg(errp
, "Cannot enable NFS readahead "
557 "if cache.direct = on");
560 client
->readahead
= qemu_opt_get_number(opts
, "readahead-size", 0);
561 if (client
->readahead
> QEMU_NFS_MAX_READAHEAD_SIZE
) {
562 error_report("NFS Warning: Truncating NFS readahead "
563 "size to %d", QEMU_NFS_MAX_READAHEAD_SIZE
);
564 client
->readahead
= QEMU_NFS_MAX_READAHEAD_SIZE
;
566 nfs_set_readahead(client
->context
, client
->readahead
);
567 #ifdef LIBNFS_FEATURE_PAGECACHE
568 nfs_set_pagecache_ttl(client
->context
, 0);
570 client
->cache_used
= true;
574 #ifdef LIBNFS_FEATURE_PAGECACHE
575 if (qemu_opt_get(opts
, "page-cache-size")) {
576 if (open_flags
& BDRV_O_NOCACHE
) {
577 error_setg(errp
, "Cannot enable NFS pagecache "
578 "if cache.direct = on");
581 client
->pagecache
= qemu_opt_get_number(opts
, "page-cache-size", 0);
582 if (client
->pagecache
> QEMU_NFS_MAX_PAGECACHE_SIZE
) {
583 error_report("NFS Warning: Truncating NFS pagecache "
584 "size to %d pages", QEMU_NFS_MAX_PAGECACHE_SIZE
);
585 client
->pagecache
= QEMU_NFS_MAX_PAGECACHE_SIZE
;
587 nfs_set_pagecache(client
->context
, client
->pagecache
);
588 nfs_set_pagecache_ttl(client
->context
, 0);
589 client
->cache_used
= true;
593 #ifdef LIBNFS_FEATURE_DEBUG
594 if (qemu_opt_get(opts
, "debug")) {
595 client
->debug
= qemu_opt_get_number(opts
, "debug", 0);
596 /* limit the maximum debug level to avoid potential flooding
597 * of our log files. */
598 if (client
->debug
> QEMU_NFS_MAX_DEBUG_LEVEL
) {
599 error_report("NFS Warning: Limiting NFS debug level "
600 "to %d", QEMU_NFS_MAX_DEBUG_LEVEL
);
601 client
->debug
= QEMU_NFS_MAX_DEBUG_LEVEL
;
603 nfs_set_debug(client
->context
, client
->debug
);
607 ret
= nfs_mount(client
->context
, client
->server
->host
, client
->path
);
609 error_setg(errp
, "Failed to mount nfs share: %s",
610 nfs_get_error(client
->context
));
614 if (flags
& O_CREAT
) {
615 ret
= nfs_creat(client
->context
, file
, 0600, &client
->fh
);
617 error_setg(errp
, "Failed to create file: %s",
618 nfs_get_error(client
->context
));
622 ret
= nfs_open(client
->context
, file
, flags
, &client
->fh
);
624 error_setg(errp
, "Failed to open file : %s",
625 nfs_get_error(client
->context
));
630 ret
= nfs_fstat(client
->context
, client
->fh
, &st
);
632 error_setg(errp
, "Failed to fstat file: %s",
633 nfs_get_error(client
->context
));
637 ret
= DIV_ROUND_UP(st
.st_size
, BDRV_SECTOR_SIZE
);
638 client
->st_blocks
= st
.st_blocks
;
639 client
->has_zero_init
= S_ISREG(st
.st_mode
);
644 nfs_client_close(client
);
651 static int nfs_file_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
653 NFSClient
*client
= bs
->opaque
;
656 client
->aio_context
= bdrv_get_aio_context(bs
);
658 ret
= nfs_client_open(client
, options
,
659 (flags
& BDRV_O_RDWR
) ? O_RDWR
: O_RDONLY
,
660 bs
->open_flags
, errp
);
664 qemu_mutex_init(&client
->mutex
);
665 bs
->total_sectors
= ret
;
670 static QemuOptsList nfs_create_opts
= {
671 .name
= "nfs-create-opts",
672 .head
= QTAILQ_HEAD_INITIALIZER(nfs_create_opts
.head
),
675 .name
= BLOCK_OPT_SIZE
,
676 .type
= QEMU_OPT_SIZE
,
677 .help
= "Virtual disk size"
679 { /* end of list */ }
683 static int nfs_file_create(const char *url
, QemuOpts
*opts
, Error
**errp
)
686 int64_t total_size
= 0;
687 NFSClient
*client
= g_new0(NFSClient
, 1);
688 QDict
*options
= NULL
;
690 client
->aio_context
= qemu_get_aio_context();
692 /* Read out options */
693 total_size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
696 options
= qdict_new();
697 ret
= nfs_parse_uri(url
, options
, errp
);
702 ret
= nfs_client_open(client
, options
, O_CREAT
, 0, errp
);
706 ret
= nfs_ftruncate(client
->context
, client
->fh
, total_size
);
707 nfs_client_close(client
);
714 static int nfs_has_zero_init(BlockDriverState
*bs
)
716 NFSClient
*client
= bs
->opaque
;
717 return client
->has_zero_init
;
720 /* Called (via nfs_service) with QemuMutex held. */
722 nfs_get_allocated_file_size_cb(int ret
, struct nfs_context
*nfs
, void *data
,
725 NFSRPC
*task
= private_data
;
727 if (task
->ret
== 0) {
728 memcpy(task
->st
, data
, sizeof(struct stat
));
731 error_report("NFS Error: %s", nfs_get_error(nfs
));
734 bdrv_wakeup(task
->bs
);
737 static int64_t nfs_get_allocated_file_size(BlockDriverState
*bs
)
739 NFSClient
*client
= bs
->opaque
;
743 if (bdrv_is_read_only(bs
) &&
744 !(bs
->open_flags
& BDRV_O_NOCACHE
)) {
745 return client
->st_blocks
* 512;
750 if (nfs_fstat_async(client
->context
, client
->fh
, nfs_get_allocated_file_size_cb
,
755 nfs_set_events(client
);
756 BDRV_POLL_WHILE(bs
, !task
.complete
);
758 return (task
.ret
< 0 ? task
.ret
: st
.st_blocks
* 512);
761 static int nfs_file_truncate(BlockDriverState
*bs
, int64_t offset
, Error
**errp
)
763 NFSClient
*client
= bs
->opaque
;
766 ret
= nfs_ftruncate(client
->context
, client
->fh
, offset
);
768 error_setg_errno(errp
, -ret
, "Failed to truncate file");
775 /* Note that this will not re-establish a connection with the NFS server
776 * - it is effectively a NOP. */
777 static int nfs_reopen_prepare(BDRVReopenState
*state
,
778 BlockReopenQueue
*queue
, Error
**errp
)
780 NFSClient
*client
= state
->bs
->opaque
;
784 if (state
->flags
& BDRV_O_RDWR
&& bdrv_is_read_only(state
->bs
)) {
785 error_setg(errp
, "Cannot open a read-only mount as read-write");
789 if ((state
->flags
& BDRV_O_NOCACHE
) && client
->cache_used
) {
790 error_setg(errp
, "Cannot disable cache if libnfs readahead or"
791 " pagecache is enabled");
795 /* Update cache for read-only reopens */
796 if (!(state
->flags
& BDRV_O_RDWR
)) {
797 ret
= nfs_fstat(client
->context
, client
->fh
, &st
);
799 error_setg(errp
, "Failed to fstat file: %s",
800 nfs_get_error(client
->context
));
803 client
->st_blocks
= st
.st_blocks
;
809 static void nfs_refresh_filename(BlockDriverState
*bs
, QDict
*options
)
811 NFSClient
*client
= bs
->opaque
;
812 QDict
*opts
= qdict_new();
813 QObject
*server_qdict
;
816 qdict_put_str(opts
, "driver", "nfs");
818 if (client
->uid
&& !client
->gid
) {
819 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
820 "nfs://%s%s?uid=%" PRId64
, client
->server
->host
, client
->path
,
822 } else if (!client
->uid
&& client
->gid
) {
823 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
824 "nfs://%s%s?gid=%" PRId64
, client
->server
->host
, client
->path
,
826 } else if (client
->uid
&& client
->gid
) {
827 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
828 "nfs://%s%s?uid=%" PRId64
"&gid=%" PRId64
,
829 client
->server
->host
, client
->path
, client
->uid
, client
->gid
);
831 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
832 "nfs://%s%s", client
->server
->host
, client
->path
);
835 ov
= qobject_output_visitor_new(&server_qdict
);
836 visit_type_NFSServer(ov
, NULL
, &client
->server
, &error_abort
);
837 visit_complete(ov
, &server_qdict
);
838 qdict_put_obj(opts
, "server", server_qdict
);
839 qdict_put_str(opts
, "path", client
->path
);
842 qdict_put_int(opts
, "user", client
->uid
);
845 qdict_put_int(opts
, "group", client
->gid
);
847 if (client
->tcp_syncnt
) {
848 qdict_put_int(opts
, "tcp-syn-cnt", client
->tcp_syncnt
);
850 if (client
->readahead
) {
851 qdict_put_int(opts
, "readahead-size", client
->readahead
);
853 if (client
->pagecache
) {
854 qdict_put_int(opts
, "page-cache-size", client
->pagecache
);
857 qdict_put_int(opts
, "debug", client
->debug
);
862 bs
->full_open_options
= opts
;
865 #ifdef LIBNFS_FEATURE_PAGECACHE
866 static void nfs_invalidate_cache(BlockDriverState
*bs
,
869 NFSClient
*client
= bs
->opaque
;
870 nfs_pagecache_invalidate(client
->context
, client
->fh
);
874 static BlockDriver bdrv_nfs
= {
875 .format_name
= "nfs",
876 .protocol_name
= "nfs",
878 .instance_size
= sizeof(NFSClient
),
879 .bdrv_parse_filename
= nfs_parse_filename
,
880 .create_opts
= &nfs_create_opts
,
882 .bdrv_has_zero_init
= nfs_has_zero_init
,
883 .bdrv_get_allocated_file_size
= nfs_get_allocated_file_size
,
884 .bdrv_truncate
= nfs_file_truncate
,
886 .bdrv_file_open
= nfs_file_open
,
887 .bdrv_close
= nfs_file_close
,
888 .bdrv_create
= nfs_file_create
,
889 .bdrv_reopen_prepare
= nfs_reopen_prepare
,
891 .bdrv_co_preadv
= nfs_co_preadv
,
892 .bdrv_co_pwritev
= nfs_co_pwritev
,
893 .bdrv_co_flush_to_disk
= nfs_co_flush
,
895 .bdrv_detach_aio_context
= nfs_detach_aio_context
,
896 .bdrv_attach_aio_context
= nfs_attach_aio_context
,
897 .bdrv_refresh_filename
= nfs_refresh_filename
,
899 #ifdef LIBNFS_FEATURE_PAGECACHE
900 .bdrv_invalidate_cache
= nfs_invalidate_cache
,
904 static void nfs_block_init(void)
906 bdrv_register(&bdrv_nfs
);
909 block_init(nfs_block_init
);