2 * QEMU Block driver for native access to files on NFS shares
4 * Copyright (c) 2014-2017 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/config-file.h"
29 #include "qemu/error-report.h"
30 #include "qapi/error.h"
31 #include "block/block_int.h"
34 #include "qemu/option.h"
36 #include "qemu/cutils.h"
37 #include "sysemu/sysemu.h"
38 #include "qapi/qapi-visit-block-core.h"
39 #include "qapi/qmp/qdict.h"
40 #include "qapi/qmp/qstring.h"
41 #include "qapi/qobject-input-visitor.h"
42 #include "qapi/qobject-output-visitor.h"
43 #include <nfsc/libnfs.h>
46 #define QEMU_NFS_MAX_READAHEAD_SIZE 1048576
47 #define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)
48 #define QEMU_NFS_MAX_DEBUG_LEVEL 2
50 typedef struct NFSClient
{
51 struct nfs_context
*context
;
55 AioContext
*aio_context
;
61 int64_t uid
, gid
, tcp_syncnt
, readahead
, pagecache
, debug
;
64 typedef struct NFSRPC
{
74 static int nfs_parse_uri(const char *filename
, QDict
*options
, Error
**errp
)
77 QueryParams
*qp
= NULL
;
80 uri
= uri_parse(filename
);
82 error_setg(errp
, "Invalid URI specified");
85 if (g_strcmp0(uri
->scheme
, "nfs") != 0) {
86 error_setg(errp
, "URI scheme must be 'nfs'");
91 error_setg(errp
, "missing hostname in URI");
96 error_setg(errp
, "missing file path in URI");
100 qp
= query_params_parse(uri
->query
);
102 error_setg(errp
, "could not parse query parameters");
106 qdict_put_str(options
, "server.host", uri
->server
);
107 qdict_put_str(options
, "server.type", "inet");
108 qdict_put_str(options
, "path", uri
->path
);
110 for (i
= 0; i
< qp
->n
; i
++) {
111 unsigned long long val
;
112 if (!qp
->p
[i
].value
) {
113 error_setg(errp
, "Value for NFS parameter expected: %s",
117 if (parse_uint_full(qp
->p
[i
].value
, &val
, 0)) {
118 error_setg(errp
, "Illegal value for NFS parameter: %s",
122 if (!strcmp(qp
->p
[i
].name
, "uid")) {
123 qdict_put_str(options
, "user", qp
->p
[i
].value
);
124 } else if (!strcmp(qp
->p
[i
].name
, "gid")) {
125 qdict_put_str(options
, "group", qp
->p
[i
].value
);
126 } else if (!strcmp(qp
->p
[i
].name
, "tcp-syncnt")) {
127 qdict_put_str(options
, "tcp-syn-count", qp
->p
[i
].value
);
128 } else if (!strcmp(qp
->p
[i
].name
, "readahead")) {
129 qdict_put_str(options
, "readahead-size", qp
->p
[i
].value
);
130 } else if (!strcmp(qp
->p
[i
].name
, "pagecache")) {
131 qdict_put_str(options
, "page-cache-size", qp
->p
[i
].value
);
132 } else if (!strcmp(qp
->p
[i
].name
, "debug")) {
133 qdict_put_str(options
, "debug", qp
->p
[i
].value
);
135 error_setg(errp
, "Unknown NFS parameter name: %s",
143 query_params_free(qp
);
151 static bool nfs_has_filename_options_conflict(QDict
*options
, Error
**errp
)
153 const QDictEntry
*qe
;
155 for (qe
= qdict_first(options
); qe
; qe
= qdict_next(options
, qe
)) {
156 if (!strcmp(qe
->key
, "host") ||
157 !strcmp(qe
->key
, "path") ||
158 !strcmp(qe
->key
, "user") ||
159 !strcmp(qe
->key
, "group") ||
160 !strcmp(qe
->key
, "tcp-syn-count") ||
161 !strcmp(qe
->key
, "readahead-size") ||
162 !strcmp(qe
->key
, "page-cache-size") ||
163 !strcmp(qe
->key
, "debug") ||
164 strstart(qe
->key
, "server.", NULL
))
166 error_setg(errp
, "Option %s cannot be used with a filename",
175 static void nfs_parse_filename(const char *filename
, QDict
*options
,
178 if (nfs_has_filename_options_conflict(options
, errp
)) {
182 nfs_parse_uri(filename
, options
, errp
);
185 static void nfs_process_read(void *arg
);
186 static void nfs_process_write(void *arg
);
188 /* Called with QemuMutex held. */
189 static void nfs_set_events(NFSClient
*client
)
191 int ev
= nfs_which_events(client
->context
);
192 if (ev
!= client
->events
) {
193 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
195 (ev
& POLLIN
) ? nfs_process_read
: NULL
,
196 (ev
& POLLOUT
) ? nfs_process_write
: NULL
,
203 static void nfs_process_read(void *arg
)
205 NFSClient
*client
= arg
;
207 qemu_mutex_lock(&client
->mutex
);
208 nfs_service(client
->context
, POLLIN
);
209 nfs_set_events(client
);
210 qemu_mutex_unlock(&client
->mutex
);
213 static void nfs_process_write(void *arg
)
215 NFSClient
*client
= arg
;
217 qemu_mutex_lock(&client
->mutex
);
218 nfs_service(client
->context
, POLLOUT
);
219 nfs_set_events(client
);
220 qemu_mutex_unlock(&client
->mutex
);
223 static void nfs_co_init_task(BlockDriverState
*bs
, NFSRPC
*task
)
226 .co
= qemu_coroutine_self(),
228 .client
= bs
->opaque
,
232 static void nfs_co_generic_bh_cb(void *opaque
)
234 NFSRPC
*task
= opaque
;
237 aio_co_wake(task
->co
);
240 /* Called (via nfs_service) with QemuMutex held. */
242 nfs_co_generic_cb(int ret
, struct nfs_context
*nfs
, void *data
,
245 NFSRPC
*task
= private_data
;
248 if (task
->ret
> 0 && task
->iov
) {
249 if (task
->ret
<= task
->iov
->size
) {
250 qemu_iovec_from_buf(task
->iov
, 0, data
, task
->ret
);
256 error_report("NFS Error: %s", nfs_get_error(nfs
));
258 aio_bh_schedule_oneshot(task
->client
->aio_context
,
259 nfs_co_generic_bh_cb
, task
);
262 static int coroutine_fn
nfs_co_preadv(BlockDriverState
*bs
, uint64_t offset
,
263 uint64_t bytes
, QEMUIOVector
*iov
,
266 NFSClient
*client
= bs
->opaque
;
269 nfs_co_init_task(bs
, &task
);
272 qemu_mutex_lock(&client
->mutex
);
273 if (nfs_pread_async(client
->context
, client
->fh
,
274 offset
, bytes
, nfs_co_generic_cb
, &task
) != 0) {
275 qemu_mutex_unlock(&client
->mutex
);
279 nfs_set_events(client
);
280 qemu_mutex_unlock(&client
->mutex
);
281 while (!task
.complete
) {
282 qemu_coroutine_yield();
289 /* zero pad short reads */
290 if (task
.ret
< iov
->size
) {
291 qemu_iovec_memset(iov
, task
.ret
, 0, iov
->size
- task
.ret
);
297 static int coroutine_fn
nfs_co_pwritev(BlockDriverState
*bs
, uint64_t offset
,
298 uint64_t bytes
, QEMUIOVector
*iov
,
301 NFSClient
*client
= bs
->opaque
;
304 bool my_buffer
= false;
306 nfs_co_init_task(bs
, &task
);
308 if (iov
->niov
!= 1) {
309 buf
= g_try_malloc(bytes
);
310 if (bytes
&& buf
== NULL
) {
313 qemu_iovec_to_buf(iov
, 0, buf
, bytes
);
316 buf
= iov
->iov
[0].iov_base
;
319 qemu_mutex_lock(&client
->mutex
);
320 if (nfs_pwrite_async(client
->context
, client
->fh
,
322 nfs_co_generic_cb
, &task
) != 0) {
323 qemu_mutex_unlock(&client
->mutex
);
330 nfs_set_events(client
);
331 qemu_mutex_unlock(&client
->mutex
);
332 while (!task
.complete
) {
333 qemu_coroutine_yield();
340 if (task
.ret
!= bytes
) {
341 return task
.ret
< 0 ? task
.ret
: -EIO
;
347 static int coroutine_fn
nfs_co_flush(BlockDriverState
*bs
)
349 NFSClient
*client
= bs
->opaque
;
352 nfs_co_init_task(bs
, &task
);
354 qemu_mutex_lock(&client
->mutex
);
355 if (nfs_fsync_async(client
->context
, client
->fh
, nfs_co_generic_cb
,
357 qemu_mutex_unlock(&client
->mutex
);
361 nfs_set_events(client
);
362 qemu_mutex_unlock(&client
->mutex
);
363 while (!task
.complete
) {
364 qemu_coroutine_yield();
370 static void nfs_detach_aio_context(BlockDriverState
*bs
)
372 NFSClient
*client
= bs
->opaque
;
374 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
375 false, NULL
, NULL
, NULL
, NULL
);
379 static void nfs_attach_aio_context(BlockDriverState
*bs
,
380 AioContext
*new_context
)
382 NFSClient
*client
= bs
->opaque
;
384 client
->aio_context
= new_context
;
385 nfs_set_events(client
);
388 static void nfs_client_close(NFSClient
*client
)
390 if (client
->context
) {
392 nfs_close(client
->context
, client
->fh
);
395 aio_set_fd_handler(client
->aio_context
, nfs_get_fd(client
->context
),
396 false, NULL
, NULL
, NULL
, NULL
);
397 nfs_destroy_context(client
->context
);
398 client
->context
= NULL
;
400 g_free(client
->path
);
401 qemu_mutex_destroy(&client
->mutex
);
402 qapi_free_NFSServer(client
->server
);
403 client
->server
= NULL
;
406 static void nfs_file_close(BlockDriverState
*bs
)
408 NFSClient
*client
= bs
->opaque
;
409 nfs_client_close(client
);
412 static int64_t nfs_client_open(NFSClient
*client
, BlockdevOptionsNfs
*opts
,
413 int flags
, int open_flags
, Error
**errp
)
415 int64_t ret
= -EINVAL
;
417 char *file
= NULL
, *strp
= NULL
;
419 qemu_mutex_init(&client
->mutex
);
421 client
->path
= g_strdup(opts
->path
);
423 strp
= strrchr(client
->path
, '/');
425 error_setg(errp
, "Invalid URL specified");
428 file
= g_strdup(strp
);
431 /* Steal the NFSServer object from opts; set the original pointer to NULL
432 * to avoid use after free and double free. */
433 client
->server
= opts
->server
;
436 client
->context
= nfs_init_context();
437 if (client
->context
== NULL
) {
438 error_setg(errp
, "Failed to init NFS context");
442 if (opts
->has_user
) {
443 client
->uid
= opts
->user
;
444 nfs_set_uid(client
->context
, client
->uid
);
447 if (opts
->has_group
) {
448 client
->gid
= opts
->group
;
449 nfs_set_gid(client
->context
, client
->gid
);
452 if (opts
->has_tcp_syn_count
) {
453 client
->tcp_syncnt
= opts
->tcp_syn_count
;
454 nfs_set_tcp_syncnt(client
->context
, client
->tcp_syncnt
);
457 #ifdef LIBNFS_FEATURE_READAHEAD
458 if (opts
->has_readahead_size
) {
459 if (open_flags
& BDRV_O_NOCACHE
) {
460 error_setg(errp
, "Cannot enable NFS readahead "
461 "if cache.direct = on");
464 client
->readahead
= opts
->readahead_size
;
465 if (client
->readahead
> QEMU_NFS_MAX_READAHEAD_SIZE
) {
466 warn_report("Truncating NFS readahead size to %d",
467 QEMU_NFS_MAX_READAHEAD_SIZE
);
468 client
->readahead
= QEMU_NFS_MAX_READAHEAD_SIZE
;
470 nfs_set_readahead(client
->context
, client
->readahead
);
471 #ifdef LIBNFS_FEATURE_PAGECACHE
472 nfs_set_pagecache_ttl(client
->context
, 0);
474 client
->cache_used
= true;
478 #ifdef LIBNFS_FEATURE_PAGECACHE
479 if (opts
->has_page_cache_size
) {
480 if (open_flags
& BDRV_O_NOCACHE
) {
481 error_setg(errp
, "Cannot enable NFS pagecache "
482 "if cache.direct = on");
485 client
->pagecache
= opts
->page_cache_size
;
486 if (client
->pagecache
> QEMU_NFS_MAX_PAGECACHE_SIZE
) {
487 warn_report("Truncating NFS pagecache size to %d pages",
488 QEMU_NFS_MAX_PAGECACHE_SIZE
);
489 client
->pagecache
= QEMU_NFS_MAX_PAGECACHE_SIZE
;
491 nfs_set_pagecache(client
->context
, client
->pagecache
);
492 nfs_set_pagecache_ttl(client
->context
, 0);
493 client
->cache_used
= true;
497 #ifdef LIBNFS_FEATURE_DEBUG
498 if (opts
->has_debug
) {
499 client
->debug
= opts
->debug
;
500 /* limit the maximum debug level to avoid potential flooding
501 * of our log files. */
502 if (client
->debug
> QEMU_NFS_MAX_DEBUG_LEVEL
) {
503 warn_report("Limiting NFS debug level to %d",
504 QEMU_NFS_MAX_DEBUG_LEVEL
);
505 client
->debug
= QEMU_NFS_MAX_DEBUG_LEVEL
;
507 nfs_set_debug(client
->context
, client
->debug
);
511 ret
= nfs_mount(client
->context
, client
->server
->host
, client
->path
);
513 error_setg(errp
, "Failed to mount nfs share: %s",
514 nfs_get_error(client
->context
));
518 if (flags
& O_CREAT
) {
519 ret
= nfs_creat(client
->context
, file
, 0600, &client
->fh
);
521 error_setg(errp
, "Failed to create file: %s",
522 nfs_get_error(client
->context
));
526 ret
= nfs_open(client
->context
, file
, flags
, &client
->fh
);
528 error_setg(errp
, "Failed to open file : %s",
529 nfs_get_error(client
->context
));
534 ret
= nfs_fstat(client
->context
, client
->fh
, &st
);
536 error_setg(errp
, "Failed to fstat file: %s",
537 nfs_get_error(client
->context
));
541 ret
= DIV_ROUND_UP(st
.st_size
, BDRV_SECTOR_SIZE
);
542 client
->st_blocks
= st
.st_blocks
;
543 client
->has_zero_init
= S_ISREG(st
.st_mode
);
548 nfs_client_close(client
);
554 static BlockdevOptionsNfs
*nfs_options_qdict_to_qapi(QDict
*options
,
557 BlockdevOptionsNfs
*opts
= NULL
;
558 QObject
*crumpled
= NULL
;
560 Error
*local_err
= NULL
;
562 crumpled
= qdict_crumple(options
, errp
);
563 if (crumpled
== NULL
) {
567 v
= qobject_input_visitor_new_keyval(crumpled
);
568 visit_type_BlockdevOptionsNfs(v
, NULL
, &opts
, &local_err
);
570 qobject_decref(crumpled
);
579 static int64_t nfs_client_open_qdict(NFSClient
*client
, QDict
*options
,
580 int flags
, int open_flags
, Error
**errp
)
582 BlockdevOptionsNfs
*opts
;
585 opts
= nfs_options_qdict_to_qapi(options
, errp
);
591 ret
= nfs_client_open(client
, opts
, flags
, open_flags
, errp
);
593 qapi_free_BlockdevOptionsNfs(opts
);
597 static int nfs_file_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
599 NFSClient
*client
= bs
->opaque
;
602 client
->aio_context
= bdrv_get_aio_context(bs
);
604 ret
= nfs_client_open_qdict(client
, options
,
605 (flags
& BDRV_O_RDWR
) ? O_RDWR
: O_RDONLY
,
606 bs
->open_flags
, errp
);
611 bs
->total_sectors
= ret
;
616 static QemuOptsList nfs_create_opts
= {
617 .name
= "nfs-create-opts",
618 .head
= QTAILQ_HEAD_INITIALIZER(nfs_create_opts
.head
),
621 .name
= BLOCK_OPT_SIZE
,
622 .type
= QEMU_OPT_SIZE
,
623 .help
= "Virtual disk size"
625 { /* end of list */ }
629 static int nfs_file_co_create(BlockdevCreateOptions
*options
, Error
**errp
)
631 BlockdevCreateOptionsNfs
*opts
= &options
->u
.nfs
;
632 NFSClient
*client
= g_new0(NFSClient
, 1);
635 assert(options
->driver
== BLOCKDEV_DRIVER_NFS
);
637 client
->aio_context
= qemu_get_aio_context();
639 ret
= nfs_client_open(client
, opts
->location
, O_CREAT
, 0, errp
);
643 ret
= nfs_ftruncate(client
->context
, client
->fh
, opts
->size
);
644 nfs_client_close(client
);
651 static int coroutine_fn
nfs_file_co_create_opts(const char *url
, QemuOpts
*opts
,
654 BlockdevCreateOptions
*create_options
;
655 BlockdevCreateOptionsNfs
*nfs_opts
;
659 create_options
= g_new0(BlockdevCreateOptions
, 1);
660 create_options
->driver
= BLOCKDEV_DRIVER_NFS
;
661 nfs_opts
= &create_options
->u
.nfs
;
663 /* Read out options */
664 nfs_opts
->size
= ROUND_UP(qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0),
667 options
= qdict_new();
668 ret
= nfs_parse_uri(url
, options
, errp
);
673 nfs_opts
->location
= nfs_options_qdict_to_qapi(options
, errp
);
674 if (nfs_opts
->location
== NULL
) {
679 ret
= nfs_file_co_create(create_options
, errp
);
687 qapi_free_BlockdevCreateOptions(create_options
);
691 static int nfs_has_zero_init(BlockDriverState
*bs
)
693 NFSClient
*client
= bs
->opaque
;
694 return client
->has_zero_init
;
697 /* Called (via nfs_service) with QemuMutex held. */
699 nfs_get_allocated_file_size_cb(int ret
, struct nfs_context
*nfs
, void *data
,
702 NFSRPC
*task
= private_data
;
704 if (task
->ret
== 0) {
705 memcpy(task
->st
, data
, sizeof(struct stat
));
708 error_report("NFS Error: %s", nfs_get_error(nfs
));
711 /* Set task->complete before reading bs->wakeup. */
712 atomic_mb_set(&task
->complete
, 1);
713 bdrv_wakeup(task
->bs
);
716 static int64_t nfs_get_allocated_file_size(BlockDriverState
*bs
)
718 NFSClient
*client
= bs
->opaque
;
722 if (bdrv_is_read_only(bs
) &&
723 !(bs
->open_flags
& BDRV_O_NOCACHE
)) {
724 return client
->st_blocks
* 512;
729 if (nfs_fstat_async(client
->context
, client
->fh
, nfs_get_allocated_file_size_cb
,
734 nfs_set_events(client
);
735 BDRV_POLL_WHILE(bs
, !task
.complete
);
737 return (task
.ret
< 0 ? task
.ret
: st
.st_blocks
* 512);
740 static int nfs_file_truncate(BlockDriverState
*bs
, int64_t offset
,
741 PreallocMode prealloc
, Error
**errp
)
743 NFSClient
*client
= bs
->opaque
;
746 if (prealloc
!= PREALLOC_MODE_OFF
) {
747 error_setg(errp
, "Unsupported preallocation mode '%s'",
748 PreallocMode_str(prealloc
));
752 ret
= nfs_ftruncate(client
->context
, client
->fh
, offset
);
754 error_setg_errno(errp
, -ret
, "Failed to truncate file");
761 /* Note that this will not re-establish a connection with the NFS server
762 * - it is effectively a NOP. */
763 static int nfs_reopen_prepare(BDRVReopenState
*state
,
764 BlockReopenQueue
*queue
, Error
**errp
)
766 NFSClient
*client
= state
->bs
->opaque
;
770 if (state
->flags
& BDRV_O_RDWR
&& bdrv_is_read_only(state
->bs
)) {
771 error_setg(errp
, "Cannot open a read-only mount as read-write");
775 if ((state
->flags
& BDRV_O_NOCACHE
) && client
->cache_used
) {
776 error_setg(errp
, "Cannot disable cache if libnfs readahead or"
777 " pagecache is enabled");
781 /* Update cache for read-only reopens */
782 if (!(state
->flags
& BDRV_O_RDWR
)) {
783 ret
= nfs_fstat(client
->context
, client
->fh
, &st
);
785 error_setg(errp
, "Failed to fstat file: %s",
786 nfs_get_error(client
->context
));
789 client
->st_blocks
= st
.st_blocks
;
795 static void nfs_refresh_filename(BlockDriverState
*bs
, QDict
*options
)
797 NFSClient
*client
= bs
->opaque
;
798 QDict
*opts
= qdict_new();
799 QObject
*server_qdict
;
802 qdict_put_str(opts
, "driver", "nfs");
804 if (client
->uid
&& !client
->gid
) {
805 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
806 "nfs://%s%s?uid=%" PRId64
, client
->server
->host
, client
->path
,
808 } else if (!client
->uid
&& client
->gid
) {
809 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
810 "nfs://%s%s?gid=%" PRId64
, client
->server
->host
, client
->path
,
812 } else if (client
->uid
&& client
->gid
) {
813 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
814 "nfs://%s%s?uid=%" PRId64
"&gid=%" PRId64
,
815 client
->server
->host
, client
->path
, client
->uid
, client
->gid
);
817 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
818 "nfs://%s%s", client
->server
->host
, client
->path
);
821 ov
= qobject_output_visitor_new(&server_qdict
);
822 visit_type_NFSServer(ov
, NULL
, &client
->server
, &error_abort
);
823 visit_complete(ov
, &server_qdict
);
824 qdict_put_obj(opts
, "server", server_qdict
);
825 qdict_put_str(opts
, "path", client
->path
);
828 qdict_put_int(opts
, "user", client
->uid
);
831 qdict_put_int(opts
, "group", client
->gid
);
833 if (client
->tcp_syncnt
) {
834 qdict_put_int(opts
, "tcp-syn-cnt", client
->tcp_syncnt
);
836 if (client
->readahead
) {
837 qdict_put_int(opts
, "readahead-size", client
->readahead
);
839 if (client
->pagecache
) {
840 qdict_put_int(opts
, "page-cache-size", client
->pagecache
);
843 qdict_put_int(opts
, "debug", client
->debug
);
848 bs
->full_open_options
= opts
;
851 #ifdef LIBNFS_FEATURE_PAGECACHE
852 static void coroutine_fn
nfs_co_invalidate_cache(BlockDriverState
*bs
,
855 NFSClient
*client
= bs
->opaque
;
856 nfs_pagecache_invalidate(client
->context
, client
->fh
);
860 static BlockDriver bdrv_nfs
= {
861 .format_name
= "nfs",
862 .protocol_name
= "nfs",
864 .instance_size
= sizeof(NFSClient
),
865 .bdrv_parse_filename
= nfs_parse_filename
,
866 .create_opts
= &nfs_create_opts
,
868 .bdrv_has_zero_init
= nfs_has_zero_init
,
869 .bdrv_get_allocated_file_size
= nfs_get_allocated_file_size
,
870 .bdrv_truncate
= nfs_file_truncate
,
872 .bdrv_file_open
= nfs_file_open
,
873 .bdrv_close
= nfs_file_close
,
874 .bdrv_co_create
= nfs_file_co_create
,
875 .bdrv_co_create_opts
= nfs_file_co_create_opts
,
876 .bdrv_reopen_prepare
= nfs_reopen_prepare
,
878 .bdrv_co_preadv
= nfs_co_preadv
,
879 .bdrv_co_pwritev
= nfs_co_pwritev
,
880 .bdrv_co_flush_to_disk
= nfs_co_flush
,
882 .bdrv_detach_aio_context
= nfs_detach_aio_context
,
883 .bdrv_attach_aio_context
= nfs_attach_aio_context
,
884 .bdrv_refresh_filename
= nfs_refresh_filename
,
886 #ifdef LIBNFS_FEATURE_PAGECACHE
887 .bdrv_co_invalidate_cache
= nfs_co_invalidate_cache
,
891 static void nfs_block_init(void)
893 bdrv_register(&bdrv_nfs
);
896 block_init(nfs_block_init
);