Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Block driver for native access to files on NFS shares |
| 3 | * |
Peter Lieven | f1a7ff7 | 2017-11-27 17:00:07 +0100 | [diff] [blame] | 4 | * Copyright (c) 2014-2017 Peter Lieven <pl@kamp.de> |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 5 | * |
| 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: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 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 |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | |
Peter Maydell | 80c71a2 | 2016-01-18 18:01:42 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 26 | |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 27 | #if !defined(_WIN32) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 28 | #include <poll.h> |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 29 | #endif |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 30 | #include "qemu/config-file.h" |
| 31 | #include "qemu/error-report.h" |
Stefan Hajnoczi | d165b8c | 2016-03-30 13:46:33 +0100 | [diff] [blame] | 32 | #include "qapi/error.h" |
Markus Armbruster | e2c1c34 | 2022-12-21 14:35:49 +0100 | [diff] [blame] | 33 | #include "block/block-io.h" |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 34 | #include "block/block_int.h" |
Max Reitz | 609f45e | 2018-06-14 21:14:28 +0200 | [diff] [blame] | 35 | #include "block/qdict.h" |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 36 | #include "trace.h" |
| 37 | #include "qemu/iov.h" |
Markus Armbruster | db72581 | 2019-08-12 07:23:50 +0200 | [diff] [blame] | 38 | #include "qemu/main-loop.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 39 | #include "qemu/module.h" |
Markus Armbruster | 922a01a | 2018-02-01 12:18:46 +0100 | [diff] [blame] | 40 | #include "qemu/option.h" |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 41 | #include "qemu/uri.h" |
Stefan Hajnoczi | 0d94b74 | 2016-03-30 13:46:34 +0100 | [diff] [blame] | 42 | #include "qemu/cutils.h" |
Pavel Dovgalyuk | e4ec5ad | 2019-09-17 14:58:19 +0300 | [diff] [blame] | 43 | #include "sysemu/replay.h" |
Markus Armbruster | 9af2398 | 2018-02-11 10:36:01 +0100 | [diff] [blame] | 44 | #include "qapi/qapi-visit-block-core.h" |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 45 | #include "qapi/qmp/qdict.h" |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 46 | #include "qapi/qmp/qstring.h" |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 47 | #include "qapi/qobject-input-visitor.h" |
| 48 | #include "qapi/qobject-output-visitor.h" |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 49 | #include <nfsc/libnfs.h> |
| 50 | |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 51 | |
Peter Lieven | 29c838c | 2015-06-26 13:14:01 +0200 | [diff] [blame] | 52 | #define QEMU_NFS_MAX_READAHEAD_SIZE 1048576 |
Peter Lieven | d99b26c | 2016-05-19 14:48:03 +0200 | [diff] [blame] | 53 | #define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE) |
Peter Lieven | 7725b8b | 2015-11-09 08:09:33 +0100 | [diff] [blame] | 54 | #define QEMU_NFS_MAX_DEBUG_LEVEL 2 |
Peter Lieven | 29c838c | 2015-06-26 13:14:01 +0200 | [diff] [blame] | 55 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 56 | typedef struct NFSClient { |
| 57 | struct nfs_context *context; |
| 58 | struct nfsfh *fh; |
| 59 | int events; |
| 60 | bool has_zero_init; |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 61 | AioContext *aio_context; |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 62 | QemuMutex mutex; |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 63 | uint64_t st_blocks; |
Peter Lieven | 38f8d5e | 2016-05-19 14:48:02 +0200 | [diff] [blame] | 64 | bool cache_used; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 65 | NFSServer *server; |
| 66 | char *path; |
| 67 | int64_t uid, gid, tcp_syncnt, readahead, pagecache, debug; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 68 | } NFSClient; |
| 69 | |
| 70 | typedef struct NFSRPC { |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 71 | BlockDriverState *bs; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 72 | int ret; |
| 73 | int complete; |
| 74 | QEMUIOVector *iov; |
| 75 | struct stat *st; |
| 76 | Coroutine *co; |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 77 | NFSClient *client; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 78 | } NFSRPC; |
| 79 | |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 80 | static int nfs_parse_uri(const char *filename, QDict *options, Error **errp) |
| 81 | { |
| 82 | URI *uri = NULL; |
| 83 | QueryParams *qp = NULL; |
| 84 | int ret = -EINVAL, i; |
| 85 | |
| 86 | uri = uri_parse(filename); |
| 87 | if (!uri) { |
| 88 | error_setg(errp, "Invalid URI specified"); |
| 89 | goto out; |
| 90 | } |
Max Reitz | f69165a | 2017-06-13 22:57:26 +0200 | [diff] [blame] | 91 | if (g_strcmp0(uri->scheme, "nfs") != 0) { |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 92 | error_setg(errp, "URI scheme must be 'nfs'"); |
| 93 | goto out; |
| 94 | } |
| 95 | |
| 96 | if (!uri->server) { |
| 97 | error_setg(errp, "missing hostname in URI"); |
| 98 | goto out; |
| 99 | } |
| 100 | |
| 101 | if (!uri->path) { |
| 102 | error_setg(errp, "missing file path in URI"); |
| 103 | goto out; |
| 104 | } |
| 105 | |
| 106 | qp = query_params_parse(uri->query); |
| 107 | if (!qp) { |
| 108 | error_setg(errp, "could not parse query parameters"); |
| 109 | goto out; |
| 110 | } |
| 111 | |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 112 | qdict_put_str(options, "server.host", uri->server); |
| 113 | qdict_put_str(options, "server.type", "inet"); |
| 114 | qdict_put_str(options, "path", uri->path); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 115 | |
| 116 | for (i = 0; i < qp->n; i++) { |
Eric Blake | bd1386c | 2023-05-22 14:04:29 -0500 | [diff] [blame] | 117 | uint64_t val; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 118 | if (!qp->p[i].value) { |
| 119 | error_setg(errp, "Value for NFS parameter expected: %s", |
| 120 | qp->p[i].name); |
| 121 | goto out; |
| 122 | } |
Eric Blake | bd1386c | 2023-05-22 14:04:29 -0500 | [diff] [blame] | 123 | if (parse_uint_full(qp->p[i].value, 0, &val)) { |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 124 | error_setg(errp, "Illegal value for NFS parameter: %s", |
| 125 | qp->p[i].name); |
| 126 | goto out; |
| 127 | } |
| 128 | if (!strcmp(qp->p[i].name, "uid")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 129 | qdict_put_str(options, "user", qp->p[i].value); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 130 | } else if (!strcmp(qp->p[i].name, "gid")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 131 | qdict_put_str(options, "group", qp->p[i].value); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 132 | } else if (!strcmp(qp->p[i].name, "tcp-syncnt")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 133 | qdict_put_str(options, "tcp-syn-count", qp->p[i].value); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 134 | } else if (!strcmp(qp->p[i].name, "readahead")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 135 | qdict_put_str(options, "readahead-size", qp->p[i].value); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 136 | } else if (!strcmp(qp->p[i].name, "pagecache")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 137 | qdict_put_str(options, "page-cache-size", qp->p[i].value); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 138 | } else if (!strcmp(qp->p[i].name, "debug")) { |
Eric Blake | 46f5ac2 | 2017-04-27 16:58:17 -0500 | [diff] [blame] | 139 | qdict_put_str(options, "debug", qp->p[i].value); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 140 | } else { |
| 141 | error_setg(errp, "Unknown NFS parameter name: %s", |
| 142 | qp->p[i].name); |
| 143 | goto out; |
| 144 | } |
| 145 | } |
| 146 | ret = 0; |
| 147 | out: |
| 148 | if (qp) { |
| 149 | query_params_free(qp); |
| 150 | } |
Heinrich Schuchardt | c2615bd | 2021-06-29 08:36:02 +0200 | [diff] [blame] | 151 | uri_free(uri); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 152 | return ret; |
| 153 | } |
| 154 | |
| 155 | static bool nfs_has_filename_options_conflict(QDict *options, Error **errp) |
| 156 | { |
| 157 | const QDictEntry *qe; |
| 158 | |
| 159 | for (qe = qdict_first(options); qe; qe = qdict_next(options, qe)) { |
| 160 | if (!strcmp(qe->key, "host") || |
| 161 | !strcmp(qe->key, "path") || |
| 162 | !strcmp(qe->key, "user") || |
| 163 | !strcmp(qe->key, "group") || |
| 164 | !strcmp(qe->key, "tcp-syn-count") || |
| 165 | !strcmp(qe->key, "readahead-size") || |
| 166 | !strcmp(qe->key, "page-cache-size") || |
Prasanna Kumar Kalever | 7103d91 | 2016-11-02 22:20:37 +0530 | [diff] [blame] | 167 | !strcmp(qe->key, "debug") || |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 168 | strstart(qe->key, "server.", NULL)) |
| 169 | { |
| 170 | error_setg(errp, "Option %s cannot be used with a filename", |
| 171 | qe->key); |
| 172 | return true; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | static void nfs_parse_filename(const char *filename, QDict *options, |
| 180 | Error **errp) |
| 181 | { |
| 182 | if (nfs_has_filename_options_conflict(options, errp)) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | nfs_parse_uri(filename, options, errp); |
| 187 | } |
| 188 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 189 | static void nfs_process_read(void *arg); |
| 190 | static void nfs_process_write(void *arg); |
| 191 | |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 192 | /* Called with QemuMutex held. */ |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 193 | static void nfs_set_events(NFSClient *client) |
| 194 | { |
| 195 | int ev = nfs_which_events(client->context); |
| 196 | if (ev != client->events) { |
Fam Zheng | dca21ef | 2015-10-23 11:08:05 +0800 | [diff] [blame] | 197 | aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 198 | (ev & POLLIN) ? nfs_process_read : NULL, |
Stefan Hajnoczi | f6a51c8 | 2016-12-01 19:26:41 +0000 | [diff] [blame] | 199 | (ev & POLLOUT) ? nfs_process_write : NULL, |
Stefan Hajnoczi | 826cc32 | 2021-12-07 13:23:31 +0000 | [diff] [blame] | 200 | NULL, NULL, client); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 201 | |
| 202 | } |
| 203 | client->events = ev; |
| 204 | } |
| 205 | |
| 206 | static void nfs_process_read(void *arg) |
| 207 | { |
| 208 | NFSClient *client = arg; |
Paolo Bonzini | 9d45665 | 2017-02-13 14:52:30 +0100 | [diff] [blame] | 209 | |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 210 | qemu_mutex_lock(&client->mutex); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 211 | nfs_service(client->context, POLLIN); |
| 212 | nfs_set_events(client); |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 213 | qemu_mutex_unlock(&client->mutex); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static void nfs_process_write(void *arg) |
| 217 | { |
| 218 | NFSClient *client = arg; |
Paolo Bonzini | 9d45665 | 2017-02-13 14:52:30 +0100 | [diff] [blame] | 219 | |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 220 | qemu_mutex_lock(&client->mutex); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 221 | nfs_service(client->context, POLLOUT); |
| 222 | nfs_set_events(client); |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 223 | qemu_mutex_unlock(&client->mutex); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Paolo Bonzini | ee15ee3 | 2022-09-22 10:49:09 +0200 | [diff] [blame] | 226 | static void coroutine_fn nfs_co_init_task(BlockDriverState *bs, NFSRPC *task) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 227 | { |
| 228 | *task = (NFSRPC) { |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 229 | .co = qemu_coroutine_self(), |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 230 | .bs = bs, |
| 231 | .client = bs->opaque, |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 232 | }; |
| 233 | } |
| 234 | |
| 235 | static void nfs_co_generic_bh_cb(void *opaque) |
| 236 | { |
| 237 | NFSRPC *task = opaque; |
Paolo Bonzini | 1919631 | 2017-02-13 14:52:31 +0100 | [diff] [blame] | 238 | |
Peter Lieven | a2c0fe2 | 2014-06-10 09:42:47 +0200 | [diff] [blame] | 239 | task->complete = 1; |
Paolo Bonzini | 1919631 | 2017-02-13 14:52:31 +0100 | [diff] [blame] | 240 | aio_co_wake(task->co); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 243 | /* Called (via nfs_service) with QemuMutex held. */ |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 244 | static void |
| 245 | nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, |
| 246 | void *private_data) |
| 247 | { |
| 248 | NFSRPC *task = private_data; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 249 | task->ret = ret; |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 250 | assert(!task->st); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 251 | if (task->ret > 0 && task->iov) { |
| 252 | if (task->ret <= task->iov->size) { |
| 253 | qemu_iovec_from_buf(task->iov, 0, data, task->ret); |
| 254 | } else { |
| 255 | task->ret = -EIO; |
| 256 | } |
| 257 | } |
Peter Lieven | 20fccb1 | 2014-03-17 09:37:21 +0100 | [diff] [blame] | 258 | if (task->ret < 0) { |
| 259 | error_report("NFS Error: %s", nfs_get_error(nfs)); |
| 260 | } |
Pavel Dovgalyuk | e4ec5ad | 2019-09-17 14:58:19 +0300 | [diff] [blame] | 261 | replay_bh_schedule_oneshot_event(task->client->aio_context, |
| 262 | nfs_co_generic_bh_cb, task); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Vladimir Sementsov-Ogievskiy | f7ef38d | 2021-09-03 13:27:59 +0300 | [diff] [blame] | 265 | static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, int64_t offset, |
| 266 | int64_t bytes, QEMUIOVector *iov, |
| 267 | BdrvRequestFlags flags) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 268 | { |
| 269 | NFSClient *client = bs->opaque; |
| 270 | NFSRPC task; |
| 271 | |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 272 | nfs_co_init_task(bs, &task); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 273 | task.iov = iov; |
| 274 | |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 275 | WITH_QEMU_LOCK_GUARD(&client->mutex) { |
| 276 | if (nfs_pread_async(client->context, client->fh, |
| 277 | offset, bytes, nfs_co_generic_cb, &task) != 0) { |
| 278 | return -ENOMEM; |
| 279 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 280 | |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 281 | nfs_set_events(client); |
| 282 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 283 | while (!task.complete) { |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 284 | qemu_coroutine_yield(); |
| 285 | } |
| 286 | |
| 287 | if (task.ret < 0) { |
| 288 | return task.ret; |
| 289 | } |
| 290 | |
| 291 | /* zero pad short reads */ |
| 292 | if (task.ret < iov->size) { |
| 293 | qemu_iovec_memset(iov, task.ret, 0, iov->size - task.ret); |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
Vladimir Sementsov-Ogievskiy | e75abed | 2021-09-03 13:28:00 +0300 | [diff] [blame] | 299 | static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, int64_t offset, |
| 300 | int64_t bytes, QEMUIOVector *iov, |
| 301 | BdrvRequestFlags flags) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 302 | { |
| 303 | NFSClient *client = bs->opaque; |
| 304 | NFSRPC task; |
| 305 | char *buf = NULL; |
Peter Lieven | ef503a8 | 2017-02-17 17:39:01 +0100 | [diff] [blame] | 306 | bool my_buffer = false; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 307 | |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 308 | nfs_co_init_task(bs, &task); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 309 | |
Peter Lieven | ef503a8 | 2017-02-17 17:39:01 +0100 | [diff] [blame] | 310 | if (iov->niov != 1) { |
| 311 | buf = g_try_malloc(bytes); |
| 312 | if (bytes && buf == NULL) { |
| 313 | return -ENOMEM; |
| 314 | } |
| 315 | qemu_iovec_to_buf(iov, 0, buf, bytes); |
| 316 | my_buffer = true; |
| 317 | } else { |
| 318 | buf = iov->iov[0].iov_base; |
Kevin Wolf | 2347dd7 | 2014-05-20 13:31:20 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 321 | WITH_QEMU_LOCK_GUARD(&client->mutex) { |
| 322 | if (nfs_pwrite_async(client->context, client->fh, |
| 323 | offset, bytes, buf, |
| 324 | nfs_co_generic_cb, &task) != 0) { |
| 325 | if (my_buffer) { |
| 326 | g_free(buf); |
| 327 | } |
| 328 | return -ENOMEM; |
Peter Lieven | ef503a8 | 2017-02-17 17:39:01 +0100 | [diff] [blame] | 329 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 330 | |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 331 | nfs_set_events(client); |
| 332 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 333 | while (!task.complete) { |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 334 | qemu_coroutine_yield(); |
| 335 | } |
| 336 | |
Peter Lieven | ef503a8 | 2017-02-17 17:39:01 +0100 | [diff] [blame] | 337 | if (my_buffer) { |
| 338 | g_free(buf); |
| 339 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 340 | |
Peter Lieven | 69785a2 | 2017-02-17 17:39:00 +0100 | [diff] [blame] | 341 | if (task.ret != bytes) { |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 342 | return task.ret < 0 ? task.ret : -EIO; |
| 343 | } |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | static int coroutine_fn nfs_co_flush(BlockDriverState *bs) |
| 349 | { |
| 350 | NFSClient *client = bs->opaque; |
| 351 | NFSRPC task; |
| 352 | |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 353 | nfs_co_init_task(bs, &task); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 354 | |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 355 | WITH_QEMU_LOCK_GUARD(&client->mutex) { |
| 356 | if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, |
| 357 | &task) != 0) { |
| 358 | return -ENOMEM; |
| 359 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 360 | |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 361 | nfs_set_events(client); |
| 362 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 363 | while (!task.complete) { |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 364 | qemu_coroutine_yield(); |
| 365 | } |
| 366 | |
| 367 | return task.ret; |
| 368 | } |
| 369 | |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 370 | static void nfs_detach_aio_context(BlockDriverState *bs) |
| 371 | { |
| 372 | NFSClient *client = bs->opaque; |
| 373 | |
Fam Zheng | dca21ef | 2015-10-23 11:08:05 +0800 | [diff] [blame] | 374 | aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), |
Stefan Hajnoczi | 60f782b | 2023-05-16 15:02:38 -0400 | [diff] [blame] | 375 | NULL, NULL, NULL, NULL, NULL); |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 376 | client->events = 0; |
| 377 | } |
| 378 | |
| 379 | static void nfs_attach_aio_context(BlockDriverState *bs, |
| 380 | AioContext *new_context) |
| 381 | { |
| 382 | NFSClient *client = bs->opaque; |
| 383 | |
| 384 | client->aio_context = new_context; |
| 385 | nfs_set_events(client); |
| 386 | } |
| 387 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 388 | static void nfs_client_close(NFSClient *client) |
| 389 | { |
| 390 | if (client->context) { |
Peter Lieven | 601dc65 | 2019-09-10 17:41:09 +0200 | [diff] [blame] | 391 | qemu_mutex_lock(&client->mutex); |
| 392 | aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), |
Stefan Hajnoczi | 60f782b | 2023-05-16 15:02:38 -0400 | [diff] [blame] | 393 | NULL, NULL, NULL, NULL, NULL); |
Peter Lieven | 601dc65 | 2019-09-10 17:41:09 +0200 | [diff] [blame] | 394 | qemu_mutex_unlock(&client->mutex); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 395 | if (client->fh) { |
| 396 | nfs_close(client->context, client->fh); |
Jeff Cody | 113fe79 | 2017-08-07 18:29:09 -0400 | [diff] [blame] | 397 | client->fh = NULL; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 398 | } |
Peter Lieven | d2c6bec | 2019-09-10 17:41:10 +0200 | [diff] [blame] | 399 | #ifdef LIBNFS_FEATURE_UMOUNT |
| 400 | nfs_umount(client->context); |
| 401 | #endif |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 402 | nfs_destroy_context(client->context); |
Jeff Cody | 113fe79 | 2017-08-07 18:29:09 -0400 | [diff] [blame] | 403 | client->context = NULL; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 404 | } |
Jeff Cody | 113fe79 | 2017-08-07 18:29:09 -0400 | [diff] [blame] | 405 | g_free(client->path); |
| 406 | qemu_mutex_destroy(&client->mutex); |
| 407 | qapi_free_NFSServer(client->server); |
| 408 | client->server = NULL; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static void nfs_file_close(BlockDriverState *bs) |
| 412 | { |
| 413 | NFSClient *client = bs->opaque; |
| 414 | nfs_client_close(client); |
| 415 | } |
| 416 | |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 417 | static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, |
Fam Zheng | cb8d4bf | 2017-04-21 20:27:05 +0800 | [diff] [blame] | 418 | int flags, int open_flags, Error **errp) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 419 | { |
Peter Lieven | f1a7ff7 | 2017-11-27 17:00:07 +0100 | [diff] [blame] | 420 | int64_t ret = -EINVAL; |
Bin Meng | ebdebe4 | 2022-09-08 21:28:15 +0800 | [diff] [blame] | 421 | #ifdef _WIN32 |
| 422 | struct __stat64 st; |
| 423 | #else |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 424 | struct stat st; |
Bin Meng | ebdebe4 | 2022-09-08 21:28:15 +0800 | [diff] [blame] | 425 | #endif |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 426 | char *file = NULL, *strp = NULL; |
| 427 | |
Jeff Cody | 113fe79 | 2017-08-07 18:29:09 -0400 | [diff] [blame] | 428 | qemu_mutex_init(&client->mutex); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 429 | |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 430 | client->path = g_strdup(opts->path); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 431 | |
| 432 | strp = strrchr(client->path, '/'); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 433 | if (strp == NULL) { |
| 434 | error_setg(errp, "Invalid URL specified"); |
| 435 | goto fail; |
| 436 | } |
| 437 | file = g_strdup(strp); |
| 438 | *strp = 0; |
| 439 | |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 440 | /* Steal the NFSServer object from opts; set the original pointer to NULL |
| 441 | * to avoid use after free and double free. */ |
| 442 | client->server = opts->server; |
| 443 | opts->server = NULL; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 444 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 445 | client->context = nfs_init_context(); |
| 446 | if (client->context == NULL) { |
| 447 | error_setg(errp, "Failed to init NFS context"); |
| 448 | goto fail; |
| 449 | } |
| 450 | |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 451 | if (opts->has_user) { |
| 452 | client->uid = opts->user; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 453 | nfs_set_uid(client->context, client->uid); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 454 | } |
| 455 | |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 456 | if (opts->has_group) { |
| 457 | client->gid = opts->group; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 458 | nfs_set_gid(client->context, client->gid); |
| 459 | } |
| 460 | |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 461 | if (opts->has_tcp_syn_count) { |
| 462 | client->tcp_syncnt = opts->tcp_syn_count; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 463 | nfs_set_tcp_syncnt(client->context, client->tcp_syncnt); |
| 464 | } |
| 465 | |
| 466 | #ifdef LIBNFS_FEATURE_READAHEAD |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 467 | if (opts->has_readahead_size) { |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 468 | if (open_flags & BDRV_O_NOCACHE) { |
| 469 | error_setg(errp, "Cannot enable NFS readahead " |
| 470 | "if cache.direct = on"); |
| 471 | goto fail; |
| 472 | } |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 473 | client->readahead = opts->readahead_size; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 474 | if (client->readahead > QEMU_NFS_MAX_READAHEAD_SIZE) { |
Alistair Francis | 3dc6f86 | 2017-07-12 06:57:41 -0700 | [diff] [blame] | 475 | warn_report("Truncating NFS readahead size to %d", |
| 476 | QEMU_NFS_MAX_READAHEAD_SIZE); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 477 | client->readahead = QEMU_NFS_MAX_READAHEAD_SIZE; |
| 478 | } |
| 479 | nfs_set_readahead(client->context, client->readahead); |
| 480 | #ifdef LIBNFS_FEATURE_PAGECACHE |
| 481 | nfs_set_pagecache_ttl(client->context, 0); |
| 482 | #endif |
| 483 | client->cache_used = true; |
| 484 | } |
| 485 | #endif |
| 486 | |
| 487 | #ifdef LIBNFS_FEATURE_PAGECACHE |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 488 | if (opts->has_page_cache_size) { |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 489 | if (open_flags & BDRV_O_NOCACHE) { |
| 490 | error_setg(errp, "Cannot enable NFS pagecache " |
| 491 | "if cache.direct = on"); |
| 492 | goto fail; |
| 493 | } |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 494 | client->pagecache = opts->page_cache_size; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 495 | if (client->pagecache > QEMU_NFS_MAX_PAGECACHE_SIZE) { |
Alistair Francis | 3dc6f86 | 2017-07-12 06:57:41 -0700 | [diff] [blame] | 496 | warn_report("Truncating NFS pagecache size to %d pages", |
| 497 | QEMU_NFS_MAX_PAGECACHE_SIZE); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 498 | client->pagecache = QEMU_NFS_MAX_PAGECACHE_SIZE; |
| 499 | } |
| 500 | nfs_set_pagecache(client->context, client->pagecache); |
| 501 | nfs_set_pagecache_ttl(client->context, 0); |
| 502 | client->cache_used = true; |
| 503 | } |
| 504 | #endif |
| 505 | |
| 506 | #ifdef LIBNFS_FEATURE_DEBUG |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 507 | if (opts->has_debug) { |
| 508 | client->debug = opts->debug; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 509 | /* limit the maximum debug level to avoid potential flooding |
| 510 | * of our log files. */ |
| 511 | if (client->debug > QEMU_NFS_MAX_DEBUG_LEVEL) { |
Alistair Francis | 3dc6f86 | 2017-07-12 06:57:41 -0700 | [diff] [blame] | 512 | warn_report("Limiting NFS debug level to %d", |
| 513 | QEMU_NFS_MAX_DEBUG_LEVEL); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 514 | client->debug = QEMU_NFS_MAX_DEBUG_LEVEL; |
| 515 | } |
| 516 | nfs_set_debug(client->context, client->debug); |
| 517 | } |
| 518 | #endif |
| 519 | |
| 520 | ret = nfs_mount(client->context, client->server->host, client->path); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 521 | if (ret < 0) { |
| 522 | error_setg(errp, "Failed to mount nfs share: %s", |
| 523 | nfs_get_error(client->context)); |
| 524 | goto fail; |
| 525 | } |
| 526 | |
| 527 | if (flags & O_CREAT) { |
| 528 | ret = nfs_creat(client->context, file, 0600, &client->fh); |
| 529 | if (ret < 0) { |
| 530 | error_setg(errp, "Failed to create file: %s", |
| 531 | nfs_get_error(client->context)); |
| 532 | goto fail; |
| 533 | } |
| 534 | } else { |
| 535 | ret = nfs_open(client->context, file, flags, &client->fh); |
| 536 | if (ret < 0) { |
| 537 | error_setg(errp, "Failed to open file : %s", |
| 538 | nfs_get_error(client->context)); |
| 539 | goto fail; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | ret = nfs_fstat(client->context, client->fh, &st); |
| 544 | if (ret < 0) { |
| 545 | error_setg(errp, "Failed to fstat file: %s", |
| 546 | nfs_get_error(client->context)); |
| 547 | goto fail; |
| 548 | } |
| 549 | |
| 550 | ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE); |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 551 | #if !defined(_WIN32) |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 552 | client->st_blocks = st.st_blocks; |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 553 | #endif |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 554 | client->has_zero_init = S_ISREG(st.st_mode); |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 555 | *strp = '/'; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 556 | goto out; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 557 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 558 | fail: |
| 559 | nfs_client_close(client); |
| 560 | out: |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 561 | g_free(file); |
| 562 | return ret; |
| 563 | } |
| 564 | |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 565 | static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options, |
| 566 | Error **errp) |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 567 | { |
| 568 | BlockdevOptionsNfs *opts = NULL; |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 569 | Visitor *v; |
Kevin Wolf | c82be42 | 2018-05-16 18:08:16 +0200 | [diff] [blame] | 570 | const QDictEntry *e; |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 571 | |
Markus Armbruster | af91062 | 2018-06-14 21:14:33 +0200 | [diff] [blame] | 572 | v = qobject_input_visitor_new_flat_confused(options, errp); |
| 573 | if (!v) { |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 574 | return NULL; |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 575 | } |
| 576 | |
Markus Armbruster | b11a093 | 2020-07-07 18:06:07 +0200 | [diff] [blame] | 577 | visit_type_BlockdevOptionsNfs(v, NULL, &opts, errp); |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 578 | visit_free(v); |
Markus Armbruster | b11a093 | 2020-07-07 18:06:07 +0200 | [diff] [blame] | 579 | if (!opts) { |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 580 | return NULL; |
| 581 | } |
| 582 | |
Kevin Wolf | c82be42 | 2018-05-16 18:08:16 +0200 | [diff] [blame] | 583 | /* Remove the processed options from the QDict (the visitor processes |
| 584 | * _all_ options in the QDict) */ |
| 585 | while ((e = qdict_first(options))) { |
| 586 | qdict_del(options, e->key); |
| 587 | } |
| 588 | |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 589 | return opts; |
| 590 | } |
| 591 | |
| 592 | static int64_t nfs_client_open_qdict(NFSClient *client, QDict *options, |
| 593 | int flags, int open_flags, Error **errp) |
| 594 | { |
| 595 | BlockdevOptionsNfs *opts; |
Peter Lieven | 182454d | 2020-12-09 13:17:35 +0100 | [diff] [blame] | 596 | int64_t ret; |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 597 | |
| 598 | opts = nfs_options_qdict_to_qapi(options, errp); |
| 599 | if (opts == NULL) { |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 600 | ret = -EINVAL; |
| 601 | goto fail; |
| 602 | } |
| 603 | |
| 604 | ret = nfs_client_open(client, opts, flags, open_flags, errp); |
| 605 | fail: |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 606 | qapi_free_BlockdevOptionsNfs(opts); |
| 607 | return ret; |
| 608 | } |
| 609 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 610 | static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags, |
| 611 | Error **errp) { |
| 612 | NFSClient *client = bs->opaque; |
| 613 | int64_t ret; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 614 | |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 615 | client->aio_context = bdrv_get_aio_context(bs); |
| 616 | |
Kevin Wolf | c22a034 | 2018-01-31 19:47:48 +0100 | [diff] [blame] | 617 | ret = nfs_client_open_qdict(client, options, |
| 618 | (flags & BDRV_O_RDWR) ? O_RDWR : O_RDONLY, |
| 619 | bs->open_flags, errp); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 620 | if (ret < 0) { |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 621 | return ret; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 622 | } |
Jeff Cody | 113fe79 | 2017-08-07 18:29:09 -0400 | [diff] [blame] | 623 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 624 | bs->total_sectors = ret; |
Eric Blake | 8f23aaf | 2020-04-28 15:28:59 -0500 | [diff] [blame] | 625 | if (client->has_zero_init) { |
| 626 | bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE; |
| 627 | } |
Simran Singhal | b3ac2b9 | 2020-04-01 22:23:14 +0530 | [diff] [blame] | 628 | return 0; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Max Reitz | fd75280 | 2014-12-02 18:32:44 +0100 | [diff] [blame] | 631 | static QemuOptsList nfs_create_opts = { |
| 632 | .name = "nfs-create-opts", |
| 633 | .head = QTAILQ_HEAD_INITIALIZER(nfs_create_opts.head), |
| 634 | .desc = { |
| 635 | { |
| 636 | .name = BLOCK_OPT_SIZE, |
| 637 | .type = QEMU_OPT_SIZE, |
| 638 | .help = "Virtual disk size" |
| 639 | }, |
| 640 | { /* end of list */ } |
| 641 | } |
| 642 | }; |
| 643 | |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 644 | static int nfs_file_co_create(BlockdevCreateOptions *options, Error **errp) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 645 | { |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 646 | BlockdevCreateOptionsNfs *opts = &options->u.nfs; |
Markus Armbruster | 5839e53 | 2014-08-19 10:31:08 +0200 | [diff] [blame] | 647 | NFSClient *client = g_new0(NFSClient, 1); |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 648 | int ret; |
| 649 | |
| 650 | assert(options->driver == BLOCKDEV_DRIVER_NFS); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 651 | |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 652 | client->aio_context = qemu_get_aio_context(); |
| 653 | |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 654 | ret = nfs_client_open(client, opts->location, O_CREAT, 0, errp); |
| 655 | if (ret < 0) { |
| 656 | goto out; |
| 657 | } |
| 658 | ret = nfs_ftruncate(client->context, client->fh, opts->size); |
| 659 | nfs_client_close(client); |
| 660 | |
| 661 | out: |
| 662 | g_free(client); |
| 663 | return ret; |
| 664 | } |
| 665 | |
Maxim Levitsky | b92902d | 2020-03-26 03:12:17 +0200 | [diff] [blame] | 666 | static int coroutine_fn nfs_file_co_create_opts(BlockDriver *drv, |
| 667 | const char *url, |
| 668 | QemuOpts *opts, |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 669 | Error **errp) |
| 670 | { |
| 671 | BlockdevCreateOptions *create_options; |
| 672 | BlockdevCreateOptionsNfs *nfs_opts; |
| 673 | QDict *options; |
| 674 | int ret; |
| 675 | |
| 676 | create_options = g_new0(BlockdevCreateOptions, 1); |
| 677 | create_options->driver = BLOCKDEV_DRIVER_NFS; |
| 678 | nfs_opts = &create_options->u.nfs; |
| 679 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 680 | /* Read out options */ |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 681 | nfs_opts->size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), |
| 682 | BDRV_SECTOR_SIZE); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 683 | |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 684 | options = qdict_new(); |
| 685 | ret = nfs_parse_uri(url, options, errp); |
| 686 | if (ret < 0) { |
| 687 | goto out; |
| 688 | } |
| 689 | |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 690 | nfs_opts->location = nfs_options_qdict_to_qapi(options, errp); |
| 691 | if (nfs_opts->location == NULL) { |
| 692 | ret = -EINVAL; |
| 693 | goto out; |
| 694 | } |
| 695 | |
| 696 | ret = nfs_file_co_create(create_options, errp); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 697 | if (ret < 0) { |
| 698 | goto out; |
| 699 | } |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 700 | |
| 701 | ret = 0; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 702 | out: |
Marc-André Lureau | cb3e7f0 | 2018-04-19 17:01:43 +0200 | [diff] [blame] | 703 | qobject_unref(options); |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 704 | qapi_free_BlockdevCreateOptions(create_options); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 705 | return ret; |
| 706 | } |
| 707 | |
| 708 | static int nfs_has_zero_init(BlockDriverState *bs) |
| 709 | { |
| 710 | NFSClient *client = bs->opaque; |
| 711 | return client->has_zero_init; |
| 712 | } |
| 713 | |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 714 | #if !defined(_WIN32) |
Paolo Bonzini | 37d1e4d | 2017-02-22 19:07:24 +0100 | [diff] [blame] | 715 | /* Called (via nfs_service) with QemuMutex held. */ |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 716 | static void |
| 717 | nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data, |
| 718 | void *private_data) |
| 719 | { |
| 720 | NFSRPC *task = private_data; |
| 721 | task->ret = ret; |
| 722 | if (task->ret == 0) { |
| 723 | memcpy(task->st, data, sizeof(struct stat)); |
| 724 | } |
| 725 | if (task->ret < 0) { |
| 726 | error_report("NFS Error: %s", nfs_get_error(nfs)); |
| 727 | } |
Paolo Bonzini | 3fe64ab | 2023-04-12 13:26:06 +0200 | [diff] [blame] | 728 | replay_bh_schedule_oneshot_event(task->client->aio_context, |
| 729 | nfs_co_generic_bh_cb, task); |
Paolo Bonzini | d746427 | 2016-10-27 12:48:57 +0200 | [diff] [blame] | 730 | } |
| 731 | |
Emanuele Giuseppe Esposito | 82618d7 | 2023-01-13 21:42:07 +0100 | [diff] [blame] | 732 | static int64_t coroutine_fn nfs_co_get_allocated_file_size(BlockDriverState *bs) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 733 | { |
| 734 | NFSClient *client = bs->opaque; |
| 735 | NFSRPC task = {0}; |
| 736 | struct stat st; |
| 737 | |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 738 | if (bdrv_is_read_only(bs) && |
| 739 | !(bs->open_flags & BDRV_O_NOCACHE)) { |
| 740 | return client->st_blocks * 512; |
| 741 | } |
| 742 | |
Paolo Bonzini | 3fe64ab | 2023-04-12 13:26:06 +0200 | [diff] [blame] | 743 | nfs_co_init_task(bs, &task); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 744 | task.st = &st; |
Paolo Bonzini | 3fe64ab | 2023-04-12 13:26:06 +0200 | [diff] [blame] | 745 | WITH_QEMU_LOCK_GUARD(&client->mutex) { |
| 746 | if (nfs_fstat_async(client->context, client->fh, nfs_get_allocated_file_size_cb, |
| 747 | &task) != 0) { |
| 748 | return -ENOMEM; |
| 749 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 750 | |
Paolo Bonzini | 3fe64ab | 2023-04-12 13:26:06 +0200 | [diff] [blame] | 751 | nfs_set_events(client); |
| 752 | } |
| 753 | while (!task.complete) { |
| 754 | qemu_coroutine_yield(); |
| 755 | } |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 756 | |
Peter Lieven | 055c6f9 | 2015-08-20 12:46:47 +0200 | [diff] [blame] | 757 | return (task.ret < 0 ? task.ret : st.st_blocks * 512); |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 758 | } |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 759 | #endif |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 760 | |
Kevin Wolf | 061ca8a | 2018-06-21 17:54:35 +0200 | [diff] [blame] | 761 | static int coroutine_fn |
Max Reitz | c80d8b0 | 2019-09-18 11:51:40 +0200 | [diff] [blame] | 762 | nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, |
Kevin Wolf | 92b9279 | 2020-04-24 14:54:39 +0200 | [diff] [blame] | 763 | PreallocMode prealloc, BdrvRequestFlags flags, |
| 764 | Error **errp) |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 765 | { |
| 766 | NFSClient *client = bs->opaque; |
Max Reitz | f59adb3 | 2017-03-28 22:51:29 +0200 | [diff] [blame] | 767 | int ret; |
| 768 | |
Max Reitz | 8243ccb | 2017-06-13 22:20:52 +0200 | [diff] [blame] | 769 | if (prealloc != PREALLOC_MODE_OFF) { |
| 770 | error_setg(errp, "Unsupported preallocation mode '%s'", |
Markus Armbruster | 977c736 | 2017-08-24 10:46:08 +0200 | [diff] [blame] | 771 | PreallocMode_str(prealloc)); |
Max Reitz | 8243ccb | 2017-06-13 22:20:52 +0200 | [diff] [blame] | 772 | return -ENOTSUP; |
| 773 | } |
| 774 | |
Max Reitz | f59adb3 | 2017-03-28 22:51:29 +0200 | [diff] [blame] | 775 | ret = nfs_ftruncate(client->context, client->fh, offset); |
| 776 | if (ret < 0) { |
| 777 | error_setg_errno(errp, -ret, "Failed to truncate file"); |
| 778 | return ret; |
| 779 | } |
| 780 | |
| 781 | return 0; |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 784 | /* Note that this will not re-establish a connection with the NFS server |
| 785 | * - it is effectively a NOP. */ |
| 786 | static int nfs_reopen_prepare(BDRVReopenState *state, |
| 787 | BlockReopenQueue *queue, Error **errp) |
| 788 | { |
| 789 | NFSClient *client = state->bs->opaque; |
Bin Meng | ebdebe4 | 2022-09-08 21:28:15 +0800 | [diff] [blame] | 790 | #ifdef _WIN32 |
| 791 | struct __stat64 st; |
| 792 | #else |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 793 | struct stat st; |
Bin Meng | ebdebe4 | 2022-09-08 21:28:15 +0800 | [diff] [blame] | 794 | #endif |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 795 | int ret = 0; |
| 796 | |
| 797 | if (state->flags & BDRV_O_RDWR && bdrv_is_read_only(state->bs)) { |
| 798 | error_setg(errp, "Cannot open a read-only mount as read-write"); |
| 799 | return -EACCES; |
| 800 | } |
| 801 | |
Peter Lieven | 38f8d5e | 2016-05-19 14:48:02 +0200 | [diff] [blame] | 802 | if ((state->flags & BDRV_O_NOCACHE) && client->cache_used) { |
Peter Lieven | d99b26c | 2016-05-19 14:48:03 +0200 | [diff] [blame] | 803 | error_setg(errp, "Cannot disable cache if libnfs readahead or" |
| 804 | " pagecache is enabled"); |
Peter Lieven | 38f8d5e | 2016-05-19 14:48:02 +0200 | [diff] [blame] | 805 | return -EINVAL; |
| 806 | } |
| 807 | |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 808 | /* Update cache for read-only reopens */ |
| 809 | if (!(state->flags & BDRV_O_RDWR)) { |
| 810 | ret = nfs_fstat(client->context, client->fh, &st); |
| 811 | if (ret < 0) { |
| 812 | error_setg(errp, "Failed to fstat file: %s", |
| 813 | nfs_get_error(client->context)); |
| 814 | return ret; |
| 815 | } |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 816 | #if !defined(_WIN32) |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 817 | client->st_blocks = st.st_blocks; |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 818 | #endif |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
Max Reitz | 998b3a1 | 2019-02-01 20:29:28 +0100 | [diff] [blame] | 824 | static void nfs_refresh_filename(BlockDriverState *bs) |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 825 | { |
| 826 | NFSClient *client = bs->opaque; |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 827 | |
| 828 | if (client->uid && !client->gid) { |
| 829 | snprintf(bs->exact_filename, sizeof(bs->exact_filename), |
| 830 | "nfs://%s%s?uid=%" PRId64, client->server->host, client->path, |
| 831 | client->uid); |
| 832 | } else if (!client->uid && client->gid) { |
| 833 | snprintf(bs->exact_filename, sizeof(bs->exact_filename), |
| 834 | "nfs://%s%s?gid=%" PRId64, client->server->host, client->path, |
| 835 | client->gid); |
| 836 | } else if (client->uid && client->gid) { |
| 837 | snprintf(bs->exact_filename, sizeof(bs->exact_filename), |
| 838 | "nfs://%s%s?uid=%" PRId64 "&gid=%" PRId64, |
| 839 | client->server->host, client->path, client->uid, client->gid); |
| 840 | } else { |
| 841 | snprintf(bs->exact_filename, sizeof(bs->exact_filename), |
| 842 | "nfs://%s%s", client->server->host, client->path); |
| 843 | } |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 844 | } |
| 845 | |
Max Reitz | 0dcbc54 | 2019-02-01 20:29:22 +0100 | [diff] [blame] | 846 | static char *nfs_dirname(BlockDriverState *bs, Error **errp) |
| 847 | { |
| 848 | NFSClient *client = bs->opaque; |
| 849 | |
| 850 | if (client->uid || client->gid) { |
| 851 | bdrv_refresh_filename(bs); |
| 852 | error_setg(errp, "Cannot generate a base directory for NFS node '%s'", |
| 853 | bs->filename); |
| 854 | return NULL; |
| 855 | } |
| 856 | |
| 857 | return g_strdup_printf("nfs://%s%s/", client->server->host, client->path); |
| 858 | } |
| 859 | |
Peter Lieven | d99b26c | 2016-05-19 14:48:03 +0200 | [diff] [blame] | 860 | #ifdef LIBNFS_FEATURE_PAGECACHE |
Paolo Bonzini | 2b148f3 | 2018-03-01 17:36:18 +0100 | [diff] [blame] | 861 | static void coroutine_fn nfs_co_invalidate_cache(BlockDriverState *bs, |
| 862 | Error **errp) |
Peter Lieven | d99b26c | 2016-05-19 14:48:03 +0200 | [diff] [blame] | 863 | { |
| 864 | NFSClient *client = bs->opaque; |
| 865 | nfs_pagecache_invalidate(client->context, client->fh); |
| 866 | } |
| 867 | #endif |
| 868 | |
Max Reitz | 2654267 | 2019-02-01 20:29:25 +0100 | [diff] [blame] | 869 | static const char *nfs_strong_runtime_opts[] = { |
| 870 | "path", |
| 871 | "user", |
| 872 | "group", |
| 873 | "server.", |
| 874 | |
| 875 | NULL |
| 876 | }; |
| 877 | |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 878 | static BlockDriver bdrv_nfs = { |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 879 | .format_name = "nfs", |
| 880 | .protocol_name = "nfs", |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 881 | |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 882 | .instance_size = sizeof(NFSClient), |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 883 | .bdrv_parse_filename = nfs_parse_filename, |
Max Reitz | fd75280 | 2014-12-02 18:32:44 +0100 | [diff] [blame] | 884 | .create_opts = &nfs_create_opts, |
| 885 | |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 886 | .bdrv_has_zero_init = nfs_has_zero_init, |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 887 | /* libnfs does not provide the allocated filesize of a file on win32. */ |
| 888 | #if !defined(_WIN32) |
Emanuele Giuseppe Esposito | 82618d7 | 2023-01-13 21:42:07 +0100 | [diff] [blame] | 889 | .bdrv_co_get_allocated_file_size = nfs_co_get_allocated_file_size, |
Yonggang Luo | c63b020 | 2020-11-05 20:31:15 +0800 | [diff] [blame] | 890 | #endif |
Kevin Wolf | 061ca8a | 2018-06-21 17:54:35 +0200 | [diff] [blame] | 891 | .bdrv_co_truncate = nfs_file_co_truncate, |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 892 | |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 893 | .bdrv_file_open = nfs_file_open, |
| 894 | .bdrv_close = nfs_file_close, |
Kevin Wolf | a1a42af | 2018-01-31 16:27:38 +0100 | [diff] [blame] | 895 | .bdrv_co_create = nfs_file_co_create, |
Stefan Hajnoczi | efc75e2 | 2018-01-18 13:43:45 +0100 | [diff] [blame] | 896 | .bdrv_co_create_opts = nfs_file_co_create_opts, |
Peter Lieven | 18a8056 | 2015-08-27 12:30:41 +0200 | [diff] [blame] | 897 | .bdrv_reopen_prepare = nfs_reopen_prepare, |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 898 | |
Peter Lieven | 69785a2 | 2017-02-17 17:39:00 +0100 | [diff] [blame] | 899 | .bdrv_co_preadv = nfs_co_preadv, |
| 900 | .bdrv_co_pwritev = nfs_co_pwritev, |
Stefan Hajnoczi | 471799d | 2014-05-08 16:34:44 +0200 | [diff] [blame] | 901 | .bdrv_co_flush_to_disk = nfs_co_flush, |
| 902 | |
| 903 | .bdrv_detach_aio_context = nfs_detach_aio_context, |
| 904 | .bdrv_attach_aio_context = nfs_attach_aio_context, |
Ashijeet Acharya | 94d6a7a | 2016-10-31 20:35:49 +0530 | [diff] [blame] | 905 | .bdrv_refresh_filename = nfs_refresh_filename, |
Max Reitz | 0dcbc54 | 2019-02-01 20:29:22 +0100 | [diff] [blame] | 906 | .bdrv_dirname = nfs_dirname, |
Peter Lieven | d99b26c | 2016-05-19 14:48:03 +0200 | [diff] [blame] | 907 | |
Max Reitz | 2654267 | 2019-02-01 20:29:25 +0100 | [diff] [blame] | 908 | .strong_runtime_opts = nfs_strong_runtime_opts, |
| 909 | |
Peter Lieven | d99b26c | 2016-05-19 14:48:03 +0200 | [diff] [blame] | 910 | #ifdef LIBNFS_FEATURE_PAGECACHE |
Paolo Bonzini | 2b148f3 | 2018-03-01 17:36:18 +0100 | [diff] [blame] | 911 | .bdrv_co_invalidate_cache = nfs_co_invalidate_cache, |
Peter Lieven | d99b26c | 2016-05-19 14:48:03 +0200 | [diff] [blame] | 912 | #endif |
Peter Lieven | 6542aa9 | 2014-02-03 10:26:13 +0100 | [diff] [blame] | 913 | }; |
| 914 | |
| 915 | static void nfs_block_init(void) |
| 916 | { |
| 917 | bdrv_register(&bdrv_nfs); |
| 918 | } |
| 919 | |
| 920 | block_init(nfs_block_init); |