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(options
, "server.host", qstring_from_str(uri
->server
));
108 qdict_put(options
, "server.type", qstring_from_str("inet"));
109 qdict_put(options
, "path", qstring_from_str(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(options
, "user",
125 qstring_from_str(qp
->p
[i
].value
));
126 } else if (!strcmp(qp
->p
[i
].name
, "gid")) {
127 qdict_put(options
, "group",
128 qstring_from_str(qp
->p
[i
].value
));
129 } else if (!strcmp(qp
->p
[i
].name
, "tcp-syncnt")) {
130 qdict_put(options
, "tcp-syn-count",
131 qstring_from_str(qp
->p
[i
].value
));
132 } else if (!strcmp(qp
->p
[i
].name
, "readahead")) {
133 qdict_put(options
, "readahead-size",
134 qstring_from_str(qp
->p
[i
].value
));
135 } else if (!strcmp(qp
->p
[i
].name
, "pagecache")) {
136 qdict_put(options
, "page-cache-size",
137 qstring_from_str(qp
->p
[i
].value
));
138 } else if (!strcmp(qp
->p
[i
].name
, "debug")) {
139 qdict_put(options
, "debug",
140 qstring_from_str(qp
->p
[i
].value
));
142 error_setg(errp
, "Unknown NFS parameter name: %s",
150 query_params_free(qp
);
158 static bool nfs_has_filename_options_conflict(QDict
*options
, Error
**errp
)
160 const QDictEntry
*qe
;
162 for (qe
= qdict_first(options
); qe
; qe
= qdict_next(options
, qe
)) {
163 if (!strcmp(qe
->key
, "host") ||
164 !strcmp(qe
->key
, "path") ||
165 !strcmp(qe
->key
, "user") ||
166 !strcmp(qe
->key
, "group") ||
167 !strcmp(qe
->key
, "tcp-syn-count") ||
168 !strcmp(qe
->key
, "readahead-size") ||
169 !strcmp(qe
->key
, "page-cache-size") ||
170 !strcmp(qe
->key
, "debug") ||
171 strstart(qe
->key
, "server.", NULL
))
173 error_setg(errp
, "Option %s cannot be used with a filename",
182 static void nfs_parse_filename(const char *filename
, QDict
*options
,
185 if (nfs_has_filename_options_conflict(options
, errp
)) {
189 nfs_parse_uri(filename
, options
, errp
);
192 static void nfs_process_read(void *arg
);
193 static void nfs_process_write(void *arg
);
195 /* Called with QemuMutex held. */
196 static void nfs_set_events(NFSClient
*client
)
198 int ev
= nfs_which_events(client
->context
);
199 if (ev
!= client
->events
) {
200 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
202 (ev
& POLLIN
) ? nfs_process_read
: NULL
,
203 (ev
& POLLOUT
) ? nfs_process_write
: NULL
,
210 static void nfs_process_read(void *arg
)
212 NFSClient
*client
= arg
;
214 qemu_mutex_lock(&client
->mutex
);
215 nfs_service(client
->context
, POLLIN
);
216 nfs_set_events(client
);
217 qemu_mutex_unlock(&client
->mutex
);
220 static void nfs_process_write(void *arg
)
222 NFSClient
*client
= arg
;
224 qemu_mutex_lock(&client
->mutex
);
225 nfs_service(client
->context
, POLLOUT
);
226 nfs_set_events(client
);
227 qemu_mutex_unlock(&client
->mutex
);
230 static void nfs_co_init_task(BlockDriverState
*bs
, NFSRPC
*task
)
233 .co
= qemu_coroutine_self(),
235 .client
= bs
->opaque
,
239 static void nfs_co_generic_bh_cb(void *opaque
)
241 NFSRPC
*task
= opaque
;
244 aio_co_wake(task
->co
);
247 /* Called (via nfs_service) with QemuMutex held. */
249 nfs_co_generic_cb(int ret
, struct nfs_context
*nfs
, void *data
,
252 NFSRPC
*task
= private_data
;
255 if (task
->ret
> 0 && task
->iov
) {
256 if (task
->ret
<= task
->iov
->size
) {
257 qemu_iovec_from_buf(task
->iov
, 0, data
, task
->ret
);
263 error_report("NFS Error: %s", nfs_get_error(nfs
));
265 aio_bh_schedule_oneshot(task
->client
->aio_context
,
266 nfs_co_generic_bh_cb
, task
);
269 static int coroutine_fn
nfs_co_preadv(BlockDriverState
*bs
, uint64_t offset
,
270 uint64_t bytes
, QEMUIOVector
*iov
,
273 NFSClient
*client
= bs
->opaque
;
276 nfs_co_init_task(bs
, &task
);
279 qemu_mutex_lock(&client
->mutex
);
280 if (nfs_pread_async(client
->context
, client
->fh
,
281 offset
, bytes
, nfs_co_generic_cb
, &task
) != 0) {
282 qemu_mutex_unlock(&client
->mutex
);
286 nfs_set_events(client
);
287 qemu_mutex_unlock(&client
->mutex
);
288 while (!task
.complete
) {
289 qemu_coroutine_yield();
296 /* zero pad short reads */
297 if (task
.ret
< iov
->size
) {
298 qemu_iovec_memset(iov
, task
.ret
, 0, iov
->size
- task
.ret
);
304 static int coroutine_fn
nfs_co_pwritev(BlockDriverState
*bs
, uint64_t offset
,
305 uint64_t bytes
, QEMUIOVector
*iov
,
308 NFSClient
*client
= bs
->opaque
;
311 bool my_buffer
= false;
313 nfs_co_init_task(bs
, &task
);
315 if (iov
->niov
!= 1) {
316 buf
= g_try_malloc(bytes
);
317 if (bytes
&& buf
== NULL
) {
320 qemu_iovec_to_buf(iov
, 0, buf
, bytes
);
323 buf
= iov
->iov
[0].iov_base
;
326 qemu_mutex_lock(&client
->mutex
);
327 if (nfs_pwrite_async(client
->context
, client
->fh
,
329 nfs_co_generic_cb
, &task
) != 0) {
330 qemu_mutex_unlock(&client
->mutex
);
337 nfs_set_events(client
);
338 qemu_mutex_unlock(&client
->mutex
);
339 while (!task
.complete
) {
340 qemu_coroutine_yield();
347 if (task
.ret
!= bytes
) {
348 return task
.ret
< 0 ? task
.ret
: -EIO
;
354 static int coroutine_fn
nfs_co_flush(BlockDriverState
*bs
)
356 NFSClient
*client
= bs
->opaque
;
359 nfs_co_init_task(bs
, &task
);
361 qemu_mutex_lock(&client
->mutex
);
362 if (nfs_fsync_async(client
->context
, client
->fh
, nfs_co_generic_cb
,
364 qemu_mutex_unlock(&client
->mutex
);
368 nfs_set_events(client
);
369 qemu_mutex_unlock(&client
->mutex
);
370 while (!task
.complete
) {
371 qemu_coroutine_yield();
377 static QemuOptsList runtime_opts
= {
379 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
383 .type
= QEMU_OPT_STRING
,
384 .help
= "Path of the image on the host",
388 .type
= QEMU_OPT_NUMBER
,
389 .help
= "UID value to use when talking to the server",
393 .type
= QEMU_OPT_NUMBER
,
394 .help
= "GID value to use when talking to the server",
397 .name
= "tcp-syn-count",
398 .type
= QEMU_OPT_NUMBER
,
399 .help
= "Number of SYNs to send during the session establish",
402 .name
= "readahead-size",
403 .type
= QEMU_OPT_NUMBER
,
404 .help
= "Set the readahead size in bytes",
407 .name
= "page-cache-size",
408 .type
= QEMU_OPT_NUMBER
,
409 .help
= "Set the pagecache size in bytes",
413 .type
= QEMU_OPT_NUMBER
,
414 .help
= "Set the NFS debug level (max 2)",
416 { /* end of list */ }
420 static void nfs_detach_aio_context(BlockDriverState
*bs
)
422 NFSClient
*client
= bs
->opaque
;
424 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
425 false, NULL
, NULL
, NULL
, NULL
);
429 static void nfs_attach_aio_context(BlockDriverState
*bs
,
430 AioContext
*new_context
)
432 NFSClient
*client
= bs
->opaque
;
434 client
->aio_context
= new_context
;
435 nfs_set_events(client
);
438 static void nfs_client_close(NFSClient
*client
)
440 if (client
->context
) {
442 nfs_close(client
->context
, client
->fh
);
444 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
445 false, NULL
, NULL
, NULL
, NULL
);
446 nfs_destroy_context(client
->context
);
448 memset(client
, 0, sizeof(NFSClient
));
451 static void nfs_file_close(BlockDriverState
*bs
)
453 NFSClient
*client
= bs
->opaque
;
454 nfs_client_close(client
);
455 qemu_mutex_destroy(&client
->mutex
);
458 static NFSServer
*nfs_config(QDict
*options
, Error
**errp
)
460 NFSServer
*server
= NULL
;
462 QObject
*crumpled_addr
= NULL
;
464 Error
*local_error
= NULL
;
466 qdict_extract_subqdict(options
, &addr
, "server.");
467 if (!qdict_size(addr
)) {
468 error_setg(errp
, "NFS server address missing");
472 crumpled_addr
= qdict_crumple(addr
, errp
);
473 if (!crumpled_addr
) {
477 iv
= qobject_input_visitor_new(crumpled_addr
, true);
478 visit_type_NFSServer(iv
, NULL
, &server
, &local_error
);
480 error_propagate(errp
, local_error
);
486 qobject_decref(crumpled_addr
);
492 static int64_t nfs_client_open(NFSClient
*client
, QDict
*options
,
493 int flags
, Error
**errp
, int open_flags
)
496 QemuOpts
*opts
= NULL
;
497 Error
*local_err
= NULL
;
499 char *file
= NULL
, *strp
= NULL
;
501 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
502 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
504 error_propagate(errp
, local_err
);
509 client
->path
= g_strdup(qemu_opt_get(opts
, "path"));
512 error_setg(errp
, "No path was specified");
516 strp
= strrchr(client
->path
, '/');
518 error_setg(errp
, "Invalid URL specified");
521 file
= g_strdup(strp
);
524 /* Pop the config into our state object, Exit if invalid */
525 client
->server
= nfs_config(options
, errp
);
526 if (!client
->server
) {
531 client
->context
= nfs_init_context();
532 if (client
->context
== NULL
) {
533 error_setg(errp
, "Failed to init NFS context");
537 if (qemu_opt_get(opts
, "user")) {
538 client
->uid
= qemu_opt_get_number(opts
, "user", 0);
539 nfs_set_uid(client
->context
, client
->uid
);
542 if (qemu_opt_get(opts
, "group")) {
543 client
->gid
= qemu_opt_get_number(opts
, "group", 0);
544 nfs_set_gid(client
->context
, client
->gid
);
547 if (qemu_opt_get(opts
, "tcp-syn-count")) {
548 client
->tcp_syncnt
= qemu_opt_get_number(opts
, "tcp-syn-count", 0);
549 nfs_set_tcp_syncnt(client
->context
, client
->tcp_syncnt
);
552 #ifdef LIBNFS_FEATURE_READAHEAD
553 if (qemu_opt_get(opts
, "readahead-size")) {
554 if (open_flags
& BDRV_O_NOCACHE
) {
555 error_setg(errp
, "Cannot enable NFS readahead "
556 "if cache.direct = on");
559 client
->readahead
= qemu_opt_get_number(opts
, "readahead-size", 0);
560 if (client
->readahead
> QEMU_NFS_MAX_READAHEAD_SIZE
) {
561 error_report("NFS Warning: Truncating NFS readahead "
562 "size to %d", QEMU_NFS_MAX_READAHEAD_SIZE
);
563 client
->readahead
= QEMU_NFS_MAX_READAHEAD_SIZE
;
565 nfs_set_readahead(client
->context
, client
->readahead
);
566 #ifdef LIBNFS_FEATURE_PAGECACHE
567 nfs_set_pagecache_ttl(client
->context
, 0);
569 client
->cache_used
= true;
573 #ifdef LIBNFS_FEATURE_PAGECACHE
574 if (qemu_opt_get(opts
, "page-cache-size")) {
575 if (open_flags
& BDRV_O_NOCACHE
) {
576 error_setg(errp
, "Cannot enable NFS pagecache "
577 "if cache.direct = on");
580 client
->pagecache
= qemu_opt_get_number(opts
, "page-cache-size", 0);
581 if (client
->pagecache
> QEMU_NFS_MAX_PAGECACHE_SIZE
) {
582 error_report("NFS Warning: Truncating NFS pagecache "
583 "size to %d pages", QEMU_NFS_MAX_PAGECACHE_SIZE
);
584 client
->pagecache
= QEMU_NFS_MAX_PAGECACHE_SIZE
;
586 nfs_set_pagecache(client
->context
, client
->pagecache
);
587 nfs_set_pagecache_ttl(client
->context
, 0);
588 client
->cache_used
= true;
592 #ifdef LIBNFS_FEATURE_DEBUG
593 if (qemu_opt_get(opts
, "debug")) {
594 client
->debug
= qemu_opt_get_number(opts
, "debug", 0);
595 /* limit the maximum debug level to avoid potential flooding
596 * of our log files. */
597 if (client
->debug
> QEMU_NFS_MAX_DEBUG_LEVEL
) {
598 error_report("NFS Warning: Limiting NFS debug level "
599 "to %d", QEMU_NFS_MAX_DEBUG_LEVEL
);
600 client
->debug
= QEMU_NFS_MAX_DEBUG_LEVEL
;
602 nfs_set_debug(client
->context
, client
->debug
);
606 ret
= nfs_mount(client
->context
, client
->server
->host
, client
->path
);
608 error_setg(errp
, "Failed to mount nfs share: %s",
609 nfs_get_error(client
->context
));
613 if (flags
& O_CREAT
) {
614 ret
= nfs_creat(client
->context
, file
, 0600, &client
->fh
);
616 error_setg(errp
, "Failed to create file: %s",
617 nfs_get_error(client
->context
));
621 ret
= nfs_open(client
->context
, file
, flags
, &client
->fh
);
623 error_setg(errp
, "Failed to open file : %s",
624 nfs_get_error(client
->context
));
629 ret
= nfs_fstat(client
->context
, client
->fh
, &st
);
631 error_setg(errp
, "Failed to fstat file: %s",
632 nfs_get_error(client
->context
));
636 ret
= DIV_ROUND_UP(st
.st_size
, BDRV_SECTOR_SIZE
);
637 client
->st_blocks
= st
.st_blocks
;
638 client
->has_zero_init
= S_ISREG(st
.st_mode
);
643 nfs_client_close(client
);
650 static int nfs_file_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
652 NFSClient
*client
= bs
->opaque
;
655 client
->aio_context
= bdrv_get_aio_context(bs
);
657 ret
= nfs_client_open(client
, options
,
658 (flags
& BDRV_O_RDWR
) ? O_RDWR
: O_RDONLY
,
659 errp
, bs
->open_flags
);
663 qemu_mutex_init(&client
->mutex
);
664 bs
->total_sectors
= ret
;
669 static QemuOptsList nfs_create_opts
= {
670 .name
= "nfs-create-opts",
671 .head
= QTAILQ_HEAD_INITIALIZER(nfs_create_opts
.head
),
674 .name
= BLOCK_OPT_SIZE
,
675 .type
= QEMU_OPT_SIZE
,
676 .help
= "Virtual disk size"
678 { /* end of list */ }
682 static int nfs_file_create(const char *url
, QemuOpts
*opts
, Error
**errp
)
685 int64_t total_size
= 0;
686 NFSClient
*client
= g_new0(NFSClient
, 1);
687 QDict
*options
= NULL
;
689 client
->aio_context
= qemu_get_aio_context();
691 /* Read out options */
692 total_size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
695 options
= qdict_new();
696 ret
= nfs_parse_uri(url
, options
, errp
);
701 ret
= nfs_client_open(client
, options
, O_CREAT
, errp
, 0);
705 ret
= nfs_ftruncate(client
->context
, client
->fh
, total_size
);
706 nfs_client_close(client
);
713 static int nfs_has_zero_init(BlockDriverState
*bs
)
715 NFSClient
*client
= bs
->opaque
;
716 return client
->has_zero_init
;
719 /* Called (via nfs_service) with QemuMutex held. */
721 nfs_get_allocated_file_size_cb(int ret
, struct nfs_context
*nfs
, void *data
,
724 NFSRPC
*task
= private_data
;
726 if (task
->ret
== 0) {
727 memcpy(task
->st
, data
, sizeof(struct stat
));
730 error_report("NFS Error: %s", nfs_get_error(nfs
));
733 bdrv_wakeup(task
->bs
);
736 static int64_t nfs_get_allocated_file_size(BlockDriverState
*bs
)
738 NFSClient
*client
= bs
->opaque
;
742 if (bdrv_is_read_only(bs
) &&
743 !(bs
->open_flags
& BDRV_O_NOCACHE
)) {
744 return client
->st_blocks
* 512;
749 if (nfs_fstat_async(client
->context
, client
->fh
, nfs_get_allocated_file_size_cb
,
754 nfs_set_events(client
);
755 BDRV_POLL_WHILE(bs
, !task
.complete
);
757 return (task
.ret
< 0 ? task
.ret
: st
.st_blocks
* 512);
760 static int nfs_file_truncate(BlockDriverState
*bs
, int64_t offset
)
762 NFSClient
*client
= bs
->opaque
;
763 return nfs_ftruncate(client
->context
, client
->fh
, offset
);
766 /* Note that this will not re-establish a connection with the NFS server
767 * - it is effectively a NOP. */
768 static int nfs_reopen_prepare(BDRVReopenState
*state
,
769 BlockReopenQueue
*queue
, Error
**errp
)
771 NFSClient
*client
= state
->bs
->opaque
;
775 if (state
->flags
& BDRV_O_RDWR
&& bdrv_is_read_only(state
->bs
)) {
776 error_setg(errp
, "Cannot open a read-only mount as read-write");
780 if ((state
->flags
& BDRV_O_NOCACHE
) && client
->cache_used
) {
781 error_setg(errp
, "Cannot disable cache if libnfs readahead or"
782 " pagecache is enabled");
786 /* Update cache for read-only reopens */
787 if (!(state
->flags
& BDRV_O_RDWR
)) {
788 ret
= nfs_fstat(client
->context
, client
->fh
, &st
);
790 error_setg(errp
, "Failed to fstat file: %s",
791 nfs_get_error(client
->context
));
794 client
->st_blocks
= st
.st_blocks
;
800 static void nfs_refresh_filename(BlockDriverState
*bs
, QDict
*options
)
802 NFSClient
*client
= bs
->opaque
;
803 QDict
*opts
= qdict_new();
804 QObject
*server_qdict
;
807 qdict_put(opts
, "driver", qstring_from_str("nfs"));
809 if (client
->uid
&& !client
->gid
) {
810 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
811 "nfs://%s%s?uid=%" PRId64
, client
->server
->host
, client
->path
,
813 } else if (!client
->uid
&& client
->gid
) {
814 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
815 "nfs://%s%s?gid=%" PRId64
, client
->server
->host
, client
->path
,
817 } else if (client
->uid
&& client
->gid
) {
818 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
819 "nfs://%s%s?uid=%" PRId64
"&gid=%" PRId64
,
820 client
->server
->host
, client
->path
, client
->uid
, client
->gid
);
822 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
823 "nfs://%s%s", client
->server
->host
, client
->path
);
826 ov
= qobject_output_visitor_new(&server_qdict
);
827 visit_type_NFSServer(ov
, NULL
, &client
->server
, &error_abort
);
828 visit_complete(ov
, &server_qdict
);
829 qdict_put_obj(opts
, "server", server_qdict
);
830 qdict_put(opts
, "path", qstring_from_str(client
->path
));
833 qdict_put(opts
, "user", qint_from_int(client
->uid
));
836 qdict_put(opts
, "group", qint_from_int(client
->gid
));
838 if (client
->tcp_syncnt
) {
839 qdict_put(opts
, "tcp-syn-cnt",
840 qint_from_int(client
->tcp_syncnt
));
842 if (client
->readahead
) {
843 qdict_put(opts
, "readahead-size",
844 qint_from_int(client
->readahead
));
846 if (client
->pagecache
) {
847 qdict_put(opts
, "page-cache-size",
848 qint_from_int(client
->pagecache
));
851 qdict_put(opts
, "debug", qint_from_int(client
->debug
));
856 bs
->full_open_options
= opts
;
859 #ifdef LIBNFS_FEATURE_PAGECACHE
860 static void nfs_invalidate_cache(BlockDriverState
*bs
,
863 NFSClient
*client
= bs
->opaque
;
864 nfs_pagecache_invalidate(client
->context
, client
->fh
);
868 static BlockDriver bdrv_nfs
= {
869 .format_name
= "nfs",
870 .protocol_name
= "nfs",
872 .instance_size
= sizeof(NFSClient
),
873 .bdrv_parse_filename
= nfs_parse_filename
,
874 .create_opts
= &nfs_create_opts
,
876 .bdrv_has_zero_init
= nfs_has_zero_init
,
877 .bdrv_get_allocated_file_size
= nfs_get_allocated_file_size
,
878 .bdrv_truncate
= nfs_file_truncate
,
880 .bdrv_file_open
= nfs_file_open
,
881 .bdrv_close
= nfs_file_close
,
882 .bdrv_create
= nfs_file_create
,
883 .bdrv_reopen_prepare
= nfs_reopen_prepare
,
885 .bdrv_co_preadv
= nfs_co_preadv
,
886 .bdrv_co_pwritev
= nfs_co_pwritev
,
887 .bdrv_co_flush_to_disk
= nfs_co_flush
,
889 .bdrv_detach_aio_context
= nfs_detach_aio_context
,
890 .bdrv_attach_aio_context
= nfs_attach_aio_context
,
891 .bdrv_refresh_filename
= nfs_refresh_filename
,
893 #ifdef LIBNFS_FEATURE_PAGECACHE
894 .bdrv_invalidate_cache
= nfs_invalidate_cache
,
898 static void nfs_block_init(void)
900 bdrv_register(&bdrv_nfs
);
903 block_init(nfs_block_init
);