1 | The following changes since commit 36f87b4513373b3cd79c87c9197d17face95d4ac: | 1 | The following changes since commit 9c125d17e9402c232c46610802e5931b3639d77b: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.10-20170630' into staging (2017-06-30 11:58:49 +0100) | 3 | Merge tag 'pull-tcg-20220420' of https://gitlab.com/rth7680/qemu into staging (2022-04-20 16:43:11 -0700) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/famz/qemu.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to c61e684e44272f2acb2bef34cf2aa234582a73a9: | 9 | for you to fetch changes up to d45c83328feab2e4083991693160f0a417cfd9b0: |
10 | 10 | ||
11 | block: Exploit BDRV_BLOCK_EOF for larger zero blocks (2017-06-30 21:48:06 +0800) | 11 | virtiofsd: Add docs/helper for killpriv_v2/no_killpriv_v2 option (2022-04-21 12:05:15 +0200) |
12 | |||
13 | ---------------------------------------------------------------- | ||
14 | Pull request | ||
15 | |||
16 | Small contrib/vhost-user-blk, contrib/vhost-user-scsi, and tools/virtiofsd | ||
17 | improvements. | ||
12 | 18 | ||
13 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
14 | 20 | ||
15 | Hi Peter, | 21 | Liu Yiding (1): |
22 | virtiofsd: Add docs/helper for killpriv_v2/no_killpriv_v2 option | ||
16 | 23 | ||
17 | Here are Eric Blake's enhancement to block layer API. Thanks! | 24 | Sakshi Kaushik (1): |
25 | Implements Backend Program conventions for vhost-user-scsi | ||
18 | 26 | ||
19 | ---------------------------------------------------------------- | 27 | Stefan Hajnoczi (1): |
28 | contrib/vhost-user-blk: add missing GOptionEntry NULL terminator | ||
20 | 29 | ||
21 | Eric Blake (2): | 30 | docs/tools/virtiofsd.rst | 5 ++ |
22 | block: Add BDRV_BLOCK_EOF to bdrv_get_block_status() | 31 | contrib/vhost-user-blk/vhost-user-blk.c | 3 +- |
23 | block: Exploit BDRV_BLOCK_EOF for larger zero blocks | 32 | contrib/vhost-user-scsi/vhost-user-scsi.c | 77 +++++++++++++++-------- |
24 | 33 | tools/virtiofsd/helper.c | 3 + | |
25 | block/io.c | 42 +++++++++++++++++++++++++++++++++--------- | 34 | 4 files changed, 62 insertions(+), 26 deletions(-) |
26 | include/block/block.h | 2 ++ | ||
27 | tests/qemu-iotests/154 | 4 ---- | ||
28 | tests/qemu-iotests/154.out | 12 ++++++------ | ||
29 | 4 files changed, 41 insertions(+), 19 deletions(-) | ||
30 | 35 | ||
31 | -- | 36 | -- |
32 | 2.9.4 | 37 | 2.35.1 |
33 | |||
34 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Sakshi Kaushik <sakshikaushik717@gmail.com> | ||
1 | 2 | ||
3 | Signed-off-by: Sakshi Kaushik <sakshikaushik717@gmail.com> | ||
4 | Message-id: 20220406162410.8536-1-sakshikaushik717@gmail.com | ||
5 | |||
6 | [Name the iSCSI URL long option --iscsi-uri instead of --iscsi_uri for | ||
7 | consistency, fix --fd which was rejected due to an outdated | ||
8 | --socket-path check, and add missing entries[] terminator. | ||
9 | --Stefan] | ||
10 | |||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | ||
13 | contrib/vhost-user-scsi/vhost-user-scsi.c | 77 +++++++++++++++-------- | ||
14 | 1 file changed, 52 insertions(+), 25 deletions(-) | ||
15 | |||
16 | diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/contrib/vhost-user-scsi/vhost-user-scsi.c | ||
19 | +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c | ||
20 | @@ -XXX,XX +XXX,XX @@ fail: | ||
21 | |||
22 | /** vhost-user-scsi **/ | ||
23 | |||
24 | +static int opt_fdnum = -1; | ||
25 | +static char *opt_socket_path; | ||
26 | +static gboolean opt_print_caps; | ||
27 | +static char *iscsi_uri; | ||
28 | + | ||
29 | +static GOptionEntry entries[] = { | ||
30 | + { "print-capabilities", 'c', 0, G_OPTION_ARG_NONE, &opt_print_caps, | ||
31 | + "Print capabilities", NULL }, | ||
32 | + { "fd", 'f', 0, G_OPTION_ARG_INT, &opt_fdnum, | ||
33 | + "Use inherited fd socket", "FDNUM" }, | ||
34 | + { "iscsi-uri", 'i', 0, G_OPTION_ARG_FILENAME, &iscsi_uri, | ||
35 | + "iSCSI URI to connect to", "FDNUM" }, | ||
36 | + { "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &opt_socket_path, | ||
37 | + "Use UNIX socket path", "PATH" }, | ||
38 | + { NULL, } | ||
39 | +}; | ||
40 | + | ||
41 | int main(int argc, char **argv) | ||
42 | { | ||
43 | VusDev *vdev_scsi = NULL; | ||
44 | - char *unix_fn = NULL; | ||
45 | - char *iscsi_uri = NULL; | ||
46 | - int lsock = -1, csock = -1, opt, err = EXIT_SUCCESS; | ||
47 | + int lsock = -1, csock = -1, err = EXIT_SUCCESS; | ||
48 | |||
49 | - while ((opt = getopt(argc, argv, "u:i:")) != -1) { | ||
50 | - switch (opt) { | ||
51 | - case 'h': | ||
52 | - goto help; | ||
53 | - case 'u': | ||
54 | - unix_fn = g_strdup(optarg); | ||
55 | - break; | ||
56 | - case 'i': | ||
57 | - iscsi_uri = g_strdup(optarg); | ||
58 | - break; | ||
59 | - default: | ||
60 | - goto help; | ||
61 | - } | ||
62 | + GError *error = NULL; | ||
63 | + GOptionContext *context; | ||
64 | + | ||
65 | + context = g_option_context_new(NULL); | ||
66 | + g_option_context_add_main_entries(context, entries, NULL); | ||
67 | + if (!g_option_context_parse(context, &argc, &argv, &error)) { | ||
68 | + g_printerr("Option parsing failed: %s\n", error->message); | ||
69 | + exit(EXIT_FAILURE); | ||
70 | + } | ||
71 | + | ||
72 | + if (opt_print_caps) { | ||
73 | + g_print("{\n"); | ||
74 | + g_print(" \"type\": \"scsi\"\n"); | ||
75 | + g_print("}\n"); | ||
76 | + goto out; | ||
77 | } | ||
78 | - if (!unix_fn || !iscsi_uri) { | ||
79 | + | ||
80 | + if (!iscsi_uri) { | ||
81 | goto help; | ||
82 | } | ||
83 | |||
84 | - lsock = unix_sock_new(unix_fn); | ||
85 | - if (lsock < 0) { | ||
86 | - goto err; | ||
87 | + if (opt_socket_path) { | ||
88 | + lsock = unix_sock_new(opt_socket_path); | ||
89 | + if (lsock < 0) { | ||
90 | + exit(EXIT_FAILURE); | ||
91 | + } | ||
92 | + } else if (opt_fdnum < 0) { | ||
93 | + g_print("%s\n", g_option_context_get_help(context, true, NULL)); | ||
94 | + exit(EXIT_FAILURE); | ||
95 | + } else { | ||
96 | + lsock = opt_fdnum; | ||
97 | } | ||
98 | |||
99 | csock = accept(lsock, NULL, NULL); | ||
100 | @@ -XXX,XX +XXX,XX @@ out: | ||
101 | if (vdev_scsi) { | ||
102 | g_main_loop_unref(vdev_scsi->loop); | ||
103 | g_free(vdev_scsi); | ||
104 | - unlink(unix_fn); | ||
105 | + unlink(opt_socket_path); | ||
106 | } | ||
107 | if (csock >= 0) { | ||
108 | close(csock); | ||
109 | @@ -XXX,XX +XXX,XX @@ out: | ||
110 | if (lsock >= 0) { | ||
111 | close(lsock); | ||
112 | } | ||
113 | - g_free(unix_fn); | ||
114 | + g_free(opt_socket_path); | ||
115 | g_free(iscsi_uri); | ||
116 | |||
117 | return err; | ||
118 | @@ -XXX,XX +XXX,XX @@ err: | ||
119 | goto out; | ||
120 | |||
121 | help: | ||
122 | - fprintf(stderr, "Usage: %s [ -u unix_sock_path -i iscsi_uri ] | [ -h ]\n", | ||
123 | + fprintf(stderr, "Usage: %s [ -s socket-path -i iscsi-uri -f fd -p print-capabilities ] | [ -h ]\n", | ||
124 | argv[0]); | ||
125 | - fprintf(stderr, " -u path to unix socket\n"); | ||
126 | - fprintf(stderr, " -i iscsi uri for lun 0\n"); | ||
127 | + fprintf(stderr, " -s, --socket-path=SOCKET_PATH path to unix socket\n"); | ||
128 | + fprintf(stderr, " -i, --iscsi-uri=ISCSI_URI iscsi uri for lun 0\n"); | ||
129 | + fprintf(stderr, " -f, --fd=FILE_DESCRIPTOR file-descriptor\n"); | ||
130 | + fprintf(stderr, " -p, --print-capabilities=PRINT_CAPABILITIES denotes print-capabilities\n"); | ||
131 | fprintf(stderr, " -h print help and quit\n"); | ||
132 | |||
133 | goto err; | ||
134 | -- | ||
135 | 2.35.1 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | The GLib documentation says "a NULL-terminated array of GOptionEntrys" |
---|---|---|---|
2 | so we'd better make sure there is a terminator that lets | ||
3 | g_option_context_add_main_entries() know when the end of the array has | ||
4 | been reached. | ||
2 | 5 | ||
3 | When we have a BDS with unallocated clusters, but asking the status | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | of its underlying bs->file or backing layer encounters an end-of-file | 7 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> |
5 | condition, we know that the rest of the unallocated area will read as | 8 | Message-id: 20220411150057.3009667-1-stefanha@redhat.com |
6 | zeroes. However, pre-patch, this required two separate calls to | 9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | bdrv_get_block_status(), as the first call stops at the point where | 10 | --- |
8 | the underlying file ends. Thanks to BDRV_BLOCK_EOF, we can now widen | 11 | contrib/vhost-user-blk/vhost-user-blk.c | 3 ++- |
9 | the results of the primary status if the secondary status already | 12 | 1 file changed, 2 insertions(+), 1 deletion(-) |
10 | includes BDRV_BLOCK_ZERO. | ||
11 | 13 | ||
12 | In turn, this fixes a TODO mentioned in iotest 154, where we can now | 14 | diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c |
13 | see that all sectors in a partial cluster at the end of a file read | ||
14 | as zero when coupling the shorter backing file's status along with our | ||
15 | knowledge that the remaining sectors came from an unallocated cluster. | ||
16 | |||
17 | Also, note that the loop in bdrv_co_get_block_status_above() had an | ||
18 | inefficent exit: in cases where the active layer sets BDRV_BLOCK_ZERO | ||
19 | but does NOT set BDRV_BLOCK_ALLOCATED (namely, where we know we read | ||
20 | zeroes merely because our unallocated clusters lie beyond the backing | ||
21 | file's shorter length), we still ended up probing the backing layer | ||
22 | even though we already had a good answer. | ||
23 | |||
24 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
25 | Message-Id: <20170505021500.19315-3-eblake@redhat.com> | ||
26 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
27 | Signed-off-by: Fam Zheng <famz@redhat.com> | ||
28 | --- | ||
29 | block/io.c | 27 ++++++++++++++++++++++----- | ||
30 | tests/qemu-iotests/154 | 4 ---- | ||
31 | tests/qemu-iotests/154.out | 12 ++++++------ | ||
32 | 3 files changed, 28 insertions(+), 15 deletions(-) | ||
33 | |||
34 | diff --git a/block/io.c b/block/io.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/block/io.c | 16 | --- a/contrib/vhost-user-blk/vhost-user-blk.c |
37 | +++ b/block/io.c | 17 | +++ b/contrib/vhost-user-blk/vhost-user-blk.c |
38 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, | 18 | @@ -XXX,XX +XXX,XX @@ static GOptionEntry entries[] = { |
39 | /* Ignore errors. This is just providing extra information, it | 19 | {"blk-file", 'b', 0, G_OPTION_ARG_FILENAME, &opt_blk_file, |
40 | * is useful but not necessary. | 20 | "block device or file path", "PATH"}, |
41 | */ | 21 | { "read-only", 'r', 0, G_OPTION_ARG_NONE, &opt_read_only, |
42 | - if (!file_pnum) { | 22 | - "Enable read-only", NULL } |
43 | - /* !file_pnum indicates an offset at or beyond the EOF; it is | 23 | + "Enable read-only", NULL }, |
44 | - * perfectly valid for the format block driver to point to such | 24 | + { NULL, }, |
45 | - * offsets, so catch it and mark everything as zero */ | 25 | }; |
46 | + if (ret2 & BDRV_BLOCK_EOF && | 26 | |
47 | + (!file_pnum || ret2 & BDRV_BLOCK_ZERO)) { | 27 | int main(int argc, char **argv) |
48 | + /* | ||
49 | + * It is valid for the format block driver to read | ||
50 | + * beyond the end of the underlying file's current | ||
51 | + * size; such areas read as zero. | ||
52 | + */ | ||
53 | ret |= BDRV_BLOCK_ZERO; | ||
54 | } else { | ||
55 | /* Limit request to the range reported by the protocol driver */ | ||
56 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverState *bs, | ||
57 | { | ||
58 | BlockDriverState *p; | ||
59 | int64_t ret = 0; | ||
60 | + bool first = true; | ||
61 | |||
62 | assert(bs != base); | ||
63 | for (p = bs; p != base; p = backing_bs(p)) { | ||
64 | ret = bdrv_co_get_block_status(p, sector_num, nb_sectors, pnum, file); | ||
65 | - if (ret < 0 || ret & BDRV_BLOCK_ALLOCATED) { | ||
66 | + if (ret < 0) { | ||
67 | + break; | ||
68 | + } | ||
69 | + if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { | ||
70 | + /* | ||
71 | + * Reading beyond the end of the file continues to read | ||
72 | + * zeroes, but we can only widen the result to the | ||
73 | + * unallocated length we learned from an earlier | ||
74 | + * iteration. | ||
75 | + */ | ||
76 | + *pnum = nb_sectors; | ||
77 | + } | ||
78 | + if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) { | ||
79 | break; | ||
80 | } | ||
81 | /* [sector_num, pnum] unallocated on this layer, which could be only | ||
82 | * the first part of [sector_num, nb_sectors]. */ | ||
83 | nb_sectors = MIN(nb_sectors, *pnum); | ||
84 | + first = false; | ||
85 | } | ||
86 | return ret; | ||
87 | } | ||
88 | diff --git a/tests/qemu-iotests/154 b/tests/qemu-iotests/154 | ||
89 | index XXXXXXX..XXXXXXX 100755 | ||
90 | --- a/tests/qemu-iotests/154 | ||
91 | +++ b/tests/qemu-iotests/154 | ||
92 | @@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io | ||
93 | $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
94 | |||
95 | # Repeat with backing file holding unallocated cluster. | ||
96 | -# TODO: Note that this forces an allocation, because we aren't yet able to | ||
97 | -# quickly detect that reads beyond EOF of the backing file are always zero | ||
98 | CLUSTER_SIZE=2048 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024)) | ||
99 | |||
100 | # Write at the front: sector-wise, the request is: | ||
101 | @@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io | ||
102 | $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
103 | |||
104 | # Repeat with backing file holding zero'd cluster | ||
105 | -# TODO: Note that this forces an allocation, because we aren't yet able to | ||
106 | -# quickly detect that reads beyond EOF of the backing file are always zero | ||
107 | $QEMU_IO -c "write -z $size 512" "$TEST_IMG.base" | _filter_qemu_io | ||
108 | |||
109 | # Write at the front: sector-wise, the request is: | ||
110 | diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out | ||
111 | index XXXXXXX..XXXXXXX 100644 | ||
112 | --- a/tests/qemu-iotests/154.out | ||
113 | +++ b/tests/qemu-iotests/154.out | ||
114 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 134217728 | ||
115 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
116 | 2048/2048 bytes allocated at offset 128 MiB | ||
117 | [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false}, | ||
118 | -{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
119 | +{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}] | ||
120 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base | ||
121 | wrote 512/512 bytes at offset 134219264 | ||
122 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
123 | 2048/2048 bytes allocated at offset 128 MiB | ||
124 | [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false}, | ||
125 | -{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
126 | +{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}] | ||
127 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base | ||
128 | wrote 1024/1024 bytes at offset 134218240 | ||
129 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
130 | 2048/2048 bytes allocated at offset 128 MiB | ||
131 | [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false}, | ||
132 | -{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
133 | +{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}] | ||
134 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base | ||
135 | wrote 2048/2048 bytes at offset 134217728 | ||
136 | 2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
137 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 134217728 | ||
138 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
139 | 2048/2048 bytes allocated at offset 128 MiB | ||
140 | [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false}, | ||
141 | -{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
142 | +{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}] | ||
143 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base | ||
144 | wrote 512/512 bytes at offset 134219264 | ||
145 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
146 | 2048/2048 bytes allocated at offset 128 MiB | ||
147 | [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false}, | ||
148 | -{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
149 | +{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}] | ||
150 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base | ||
151 | wrote 1024/1024 bytes at offset 134218240 | ||
152 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
153 | 2048/2048 bytes allocated at offset 128 MiB | ||
154 | [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false}, | ||
155 | -{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
156 | +{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}] | ||
157 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base | ||
158 | wrote 2048/2048 bytes at offset 134217728 | ||
159 | 2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
160 | -- | 28 | -- |
161 | 2.9.4 | 29 | 2.35.1 |
162 | |||
163 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: Liu Yiding <liuyd.fnst@fujitsu.com> |
---|---|---|---|
2 | 2 | ||
3 | Just as the block layer already sets BDRV_BLOCK_ALLOCATED as a | 3 | virtiofsd has introduced killpriv_v2/no_killpriv_v2 for a while. Add |
4 | shortcut for subsequent operations, there are also some optimizations | 4 | description of it to docs/helper. |
5 | that are made easier if we can quickly tell that *pnum will advance | ||
6 | us to the end of a file, via a new BDRV_BLOCK_EOF which gets set | ||
7 | by the block layer. | ||
8 | 5 | ||
9 | This just plumbs up the new bit; subsequent patches will make use | 6 | Signed-off-by: Liu Yiding <liuyd.fnst@fujitsu.com> |
10 | of it. | 7 | Message-Id: <20220421095151.2231099-1-liuyd.fnst@fujitsu.com> |
11 | 8 | ||
12 | Signed-off-by: Eric Blake <eblake@redhat.com> | 9 | [Small documentation fixes: s/as client supports/as the client supports/ |
13 | Message-Id: <20170505021500.19315-2-eblake@redhat.com> | 10 | and s/. /. /. |
14 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | --Stefan] |
15 | Signed-off-by: Fam Zheng <famz@redhat.com> | 12 | |
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | --- | 14 | --- |
17 | block/io.c | 15 +++++++++++---- | 15 | docs/tools/virtiofsd.rst | 5 +++++ |
18 | include/block/block.h | 2 ++ | 16 | tools/virtiofsd/helper.c | 3 +++ |
19 | 2 files changed, 13 insertions(+), 4 deletions(-) | 17 | 2 files changed, 8 insertions(+) |
20 | 18 | ||
21 | diff --git a/block/io.c b/block/io.c | 19 | diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst |
22 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/block/io.c | 21 | --- a/docs/tools/virtiofsd.rst |
24 | +++ b/block/io.c | 22 | +++ b/docs/tools/virtiofsd.rst |
25 | @@ -XXX,XX +XXX,XX @@ typedef struct BdrvCoGetBlockStatusData { | 23 | @@ -XXX,XX +XXX,XX @@ Options |
26 | * Drivers not implementing the functionality are assumed to not support | 24 | label. Server will try to set that label on newly created file |
27 | * backing files, hence all their sectors are reported as allocated. | 25 | atomically wherever possible. |
28 | * | 26 | |
29 | - * If 'sector_num' is beyond the end of the disk image the return value is 0 | 27 | + * killpriv_v2|no_killpriv_v2 - |
30 | - * and 'pnum' is set to 0. | 28 | + Enable/disable ``FUSE_HANDLE_KILLPRIV_V2`` support. KILLPRIV_V2 is enabled |
31 | + * If 'sector_num' is beyond the end of the disk image the return value is | 29 | + by default as long as the client supports it. Enabling this option helps |
32 | + * BDRV_BLOCK_EOF and 'pnum' is set to 0. | 30 | + with performance in write path. |
33 | * | 31 | + |
34 | * 'pnum' is set to the number of sectors (including and immediately following | 32 | .. option:: --socket-path=PATH |
35 | * the specified sector) that are known to be in the same | 33 | |
36 | * allocated/unallocated state. | 34 | Listen on vhost-user UNIX domain socket at PATH. |
37 | * | 35 | diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c |
38 | * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes | 36 | index XXXXXXX..XXXXXXX 100644 |
39 | - * beyond the end of the disk image it will be clamped. | 37 | --- a/tools/virtiofsd/helper.c |
40 | + * beyond the end of the disk image it will be clamped; if 'pnum' is set to | 38 | +++ b/tools/virtiofsd/helper.c |
41 | + * the end of the image, then the returned value will include BDRV_BLOCK_EOF. | 39 | @@ -XXX,XX +XXX,XX @@ void fuse_cmdline_help(void) |
42 | * | 40 | " -o announce_submounts Announce sub-mount points to the guest\n" |
43 | * If returned value is positive and BDRV_BLOCK_OFFSET_VALID bit is set, 'file' | 41 | " -o posix_acl/no_posix_acl Enable/Disable posix_acl. (default: disabled)\n" |
44 | * points to the BDS which the sector range is allocated in. | 42 | " -o security_label/no_security_label Enable/Disable security label. (default: disabled)\n" |
45 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, | 43 | + " -o killpriv_v2/no_killpriv_v2\n" |
46 | 44 | + " Enable/Disable FUSE_HANDLE_KILLPRIV_V2.\n" | |
47 | if (sector_num >= total_sectors) { | 45 | + " (default: enabled as long as client supports it)\n" |
48 | *pnum = 0; | 46 | ); |
49 | - return 0; | ||
50 | + return BDRV_BLOCK_EOF; | ||
51 | } | ||
52 | |||
53 | n = total_sectors - sector_num; | ||
54 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, | ||
55 | if (!bs->drv->bdrv_co_get_block_status) { | ||
56 | *pnum = nb_sectors; | ||
57 | ret = BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; | ||
58 | + if (sector_num + nb_sectors == total_sectors) { | ||
59 | + ret |= BDRV_BLOCK_EOF; | ||
60 | + } | ||
61 | if (bs->drv->protocol_name) { | ||
62 | ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE); | ||
63 | } | ||
64 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, | ||
65 | |||
66 | out: | ||
67 | bdrv_dec_in_flight(bs); | ||
68 | + if (ret >= 0 && sector_num + *pnum == total_sectors) { | ||
69 | + ret |= BDRV_BLOCK_EOF; | ||
70 | + } | ||
71 | return ret; | ||
72 | } | 47 | } |
73 | 48 | ||
74 | diff --git a/include/block/block.h b/include/block/block.h | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/include/block/block.h | ||
77 | +++ b/include/block/block.h | ||
78 | @@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry { | ||
79 | * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data | ||
80 | * BDRV_BLOCK_ALLOCATED: the content of the block is determined by this | ||
81 | * layer (short for DATA || ZERO), set by block layer | ||
82 | + * BDRV_BLOCK_EOF: the returned pnum covers through end of file for this layer | ||
83 | * | ||
84 | * Internal flag: | ||
85 | * BDRV_BLOCK_RAW: used internally to indicate that the request was | ||
86 | @@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry { | ||
87 | #define BDRV_BLOCK_OFFSET_VALID 0x04 | ||
88 | #define BDRV_BLOCK_RAW 0x08 | ||
89 | #define BDRV_BLOCK_ALLOCATED 0x10 | ||
90 | +#define BDRV_BLOCK_EOF 0x20 | ||
91 | #define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASK | ||
92 | |||
93 | typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue; | ||
94 | -- | 49 | -- |
95 | 2.9.4 | 50 | 2.35.1 |
96 | |||
97 | diff view generated by jsdifflib |