search for: file_zero

Displaying 20 results from an estimated 51 matches for "file_zero".

2019 Jan 05
0
[PATCH nbdkit v2 07/11] file: Implement NBDKIT_API_VERSION 2.
..., uint32_t count, uint64_t offset) offset += r; } + if ((flags & NBDKIT_FLAG_FUA) && file_flush (handle, 0) == -1) + return -1; + return 0; } @@ -323,20 +350,20 @@ do_fallocate(int fd, int mode, off_t offset, off_t len) /* Write zeroes to the file. */ static int -file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) +file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) { struct handle *h = handle; int r; #ifdef FALLOC_FL_PUNCH_HOLE - if (h->can_punch_hole && may_trim) { + if (h->can_punch_hole &&amp...
2018 Jan 31
1
[nbdkit PATCH] file: Add trim support
...ad data from the file. */ static int file_pread (void *handle, void *buf, uint32_t count, uint64_t offset) @@ -219,7 +231,7 @@ file_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset) return 0; } -/* Write data to the file. */ +/* Write zeroes to the file. */ static int file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) { @@ -268,6 +280,33 @@ file_flush (void *handle) return 0; } +/* Punch a hole in the file. */ +static int +file_trim (void *handle, uint32_t count, uint64_t offset) +{ + int r = -1; +#ifdef FALLOC_FL_PUNCH_HOLE + struct handle *h...
2018 Jul 27
4
[PATCH] file: Fix zero/trim with block device
...uild nbdkit on RHEL, but the change is pretty trivial. --- plugins/file/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/file/file.c b/plugins/file/file.c index b6e33de..a7c07fb 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -243,7 +243,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) if (may_trim) { r = fallocate (h->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, count); - if (r == -1 && errno != EOPNOTSUPP) { + if (r == -1 && errno != EOPNOTSUPP && errno != ENO...
2018 Jul 28
1
Re: [PATCH] file: Fix zero/trim with block device
...ins/file/file.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > >diff --git a/plugins/file/file.c b/plugins/file/file.c > >index b6e33de..a7c07fb 100644 > >--- a/plugins/file/file.c > >+++ b/plugins/file/file.c > >@@ -243,7 +243,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) > > if (may_trim) { > > r = fallocate (h->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, > > offset, count); > >- if (r == -1 && errno != EOPNOTSUPP) { > >+ if (r == -1 &&...
2018 Jul 30
3
[PATCH v2] file: Normalize errno value for ENODEV
...el 3.10 fails with ENODEV for block device. Kernel >= 4.9 fails + with EOPNOTSUPP in this case. Normalize errno to simplify callers. */ + if (r == -1 && errno == ENODEV) { + errno = EOPNOTSUPP; + } + return r; +} +#endif + static void file_unload (void) { @@ -241,9 +256,9 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) #ifdef FALLOC_FL_PUNCH_HOLE if (may_trim) { - r = fallocate (h->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - offset, count); - if (r == -1 && errno != EOPNOTSUPP && errno != ENODEV) { + r = do_f...
2018 Jul 28
3
[PATCH] file: Normalize errno value for ENODEV
...nel 3.10 fails with ENODEV for block device. Kernel >= 4.9 fails + with EOPNOTSUPP in this case. Normlize errno to simplify callers. */ + if (r == -1 && errno == ENODEV) { + errno = EOPNOTSUPP; + } + return r; +} +#endif + static void file_unload (void) { @@ -241,9 +256,9 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) #ifdef FALLOC_FL_PUNCH_HOLE if (may_trim) { - r = fallocate (h->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - offset, count); - if (r == -1 && errno != EOPNOTSUPP && errno != ENODEV) { + r = do_f...
2018 Aug 21
1
Re: [PATCH v3 0/4] file: Zero for block devices and older file systems
FYI I added a few enhancements to allow easier tracing inside the file plugin: https://github.com/libguestfs/nbdkit/commit/10d4dcfb30cb0ba626a2ec503c7c96f72c6ca88e https://github.com/libguestfs/nbdkit/commit/96a41cd798ec0dce07d97c2a4a04ee6284e1552f I learned from this that the file_zero function does successfully use fallocate to zero ranges, at least on my very recent Linux system. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to v...
2019 Aug 13
0
[nbdkit PATCH 2/2] plugins: Permit ENOTSUP as synonym for EOPNOTSUPP
...ile/file.c @@ -73,6 +73,12 @@ static pthread_mutex_t lseek_lock = PTHREAD_MUTEX_INITIALIZER; /* to enable: -D file.zero=1 */ int file_debug_zero; +static bool +file_is_enotsup (int err) +{ + return err == ENOTSUP || err == EOPNOTSUPP; +} + static void file_unload (void) { @@ -399,7 +405,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) goto out; } - if (errno != EOPNOTSUPP) { + if (!file_is_enotsup (errno)) { nbdkit_error ("zero: %m"); return -1; } @@ -418,7 +424,7 @@ file_zero (void *handle, uint32_t count, uint64_t of...
2018 Jul 27
0
Re: [PATCH] file: Fix zero/trim with block device
...rivial. > --- > plugins/file/file.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/plugins/file/file.c b/plugins/file/file.c > index b6e33de..a7c07fb 100644 > --- a/plugins/file/file.c > +++ b/plugins/file/file.c > @@ -243,7 +243,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) > if (may_trim) { > r = fallocate (h->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, > offset, count); > - if (r == -1 && errno != EOPNOTSUPP) { > + if (r == -1 && errno != EOPNOT...
2019 Aug 13
3
[nbdkit PATCH 0/2] errno cleanup patches
I ran into these while trying to prepare patches to add NBD_CMD_FLAG_FAST_ZERO, which will expose a new NBD_ENOTSUP wire value. Eric Blake (2): plugins: Don't lose original error when emulating FUA plugins: Permit ENOTSUP as synonym for EOPNOTSUPP docs/nbdkit-filter.pod | 11 ++++++----- docs/nbdkit-plugin.pod | 12 +++++++----- plugins/file/file.c | 16 +++++++++++-----
2018 Aug 02
2
Re: [PATCH 3/3] file: Zero for block devices on old kernels
...fall back... > + } > + } > +#else > + h->sector_size = 4096; /* Safe guess */ ...to the safe guess, instead of giving up entirely? (Might matter on a system with newer headers that have the macro, but where the kernel does not support the ioctl). > @@ -329,6 +361,20 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) > } > #endif > > +#ifdef BLKZEROOUT > + /* For aligned range and block devices, we can use BLKZEROOUT. */ > + if (h->is_block_device && is_aligned (h, offset) && is_aligned (h, count)) { S...
2019 Jan 04
10
[PATCH nbdkit 0/7] server: Implement NBD_FLAG_CAN_MULTI_CONN.
First thing to say is that I need to do a *lot* more testing on this, so this is just an early peek. In particular, although it passed ‘make check && make check-valgrind’ I have *not* tested it against a multi-conn-aware client such as the Linux kernel >= 4.9. This implements NBD_FLAG_CAN_MULTI_CONN, described in the protocol doc as: "NBD_FLAG_CAN_MULTI_CONN: Indicates that
2018 Aug 18
7
[PATCH v3 0/4] file: Zero for block devices and older file systems
This version addresses some of the comments on v2. Changes since v2: - file_zero: Add missing space in function call - is_aligned: Assert that align is indeed a power of 2 - Spelling in commit message Not changed: - Eric commented that spacing was off: https://www.redhat.com/archives/libguestfs/2018-August/msg00113.html but I could not find anything wrong. - Eric asked if...
2018 Aug 19
9
[PATCH v3 0/4] file: Zero for block devices and older file systems
This version addresses comments on v3. Changes since v3: - Finally got spacing right (Eric) - Reorder includes (Richard) - Return 0 or -1 instead of r (Richard) - Add common/include/isaligned.h to Makefile.am (Richard) v3 was here: https://www.redhat.com/archives/libguestfs/2018-August/msg00177.html Nir Soffer (4): file: Avoid unsupported fallocate() calls file: Support zero without
2018 Aug 02
10
[PATCH 0/3] file: Zero for block devices and older file systems
This is the second version to support efficient zero for block devices on older kernels (e.g. RHEL 7.5), and file systems that do not support yet FALLOC_FS_ZERO_RANGE (e.g. NFS 4.2). Changes since v1: - Split to smaller patches - Skip linux only includes on other systems - Skip code using BLKZEROOUT if the macro is not defined - Try BLKZEROOUT only if the offset and count are aligned to device
2019 Jan 05
15
[PATCH nbdkit v2 01/11] server: Implement NBD_FLAG_CAN_MULTI_CONN.
For existing commits, this is almost identical to v1, except that I updated some commit messages and reordered the commits in a somewhat more logical sequence. The main changes are the extra commits: [06/11] plugins: Return NBD_FLAG_CAN_MULTI_CONN from some readonly plugins. - Readonly plugins that can set the flag unconditionally. [09/11] partitioning: Return NBD_FLAG_CAN_MULTI_CONN. [10/11]
2018 Sep 17
4
[PATCH nbdkit v2] common: isaligned: Use a macro instead of relying on implicit truncation.
...assert (is_power_of_2 ((align))); \ + !((size) & ((align) - 1)); \ +}) #endif /* NBDKIT_ISALIGNED_H */ diff --git a/plugins/file/file.c b/plugins/file/file.c index 9d03f18..1391f62 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -397,13 +397,13 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) #ifdef BLKZEROOUT /* For aligned range and block device, we can use BLKZEROOUT. */ - if (h->can_zeroout && is_aligned (offset | count, h->sector_size)) { + if (h->can_zeroout && IS_ALIGNED (offset | count...
2018 Aug 03
10
[PATCH v2 0/4] file: Zero for block devices and older file systems
This is the third version to support efficient zero for block devices on older kernels (e.g. RHEL 7.5), and file systems that do not support yet FALLOC_FS_ZERO_RANGE (e.g. NFS 4.2). Changes since v2: - Revert file_can_trim change, since it is too late to change the value after negotiation. Changing the capability dinamically may be useful internally, but it should be done via other means. -
2018 Sep 17
0
[PATCH nbdkit v3 1/3] common: isaligned: Use a macro instead of relying on implicit truncation.
...assert (is_power_of_2 ((align))); \ + !((size) & ((align) - 1)); \ +}) #endif /* NBDKIT_ISALIGNED_H */ diff --git a/plugins/file/file.c b/plugins/file/file.c index 9d03f18..1391f62 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -397,13 +397,13 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) #ifdef BLKZEROOUT /* For aligned range and block device, we can use BLKZEROOUT. */ - if (h->can_zeroout && is_aligned (offset | count, h->sector_size)) { + if (h->can_zeroout && IS_ALIGNED (offset | count...
2018 Aug 02
0
[PATCH 2/3] file: Support zero without ZERO_RANGE
...t handle { int fd; bool can_punch_hole; bool can_zero_range; + bool can_fallocate; }; /* Create the per-connection handle. */ @@ -161,6 +162,8 @@ file_open (int readonly) h->can_zero_range = false; #endif + h->can_fallocate = true; + return h; } @@ -297,6 +300,35 @@ file_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) } #endif +#ifdef FALLOC_FL_PUNCH_HOLE + /* If we can punch hole but may not trim, we can combine punching hole and + fallocate to zero a range. This is expected to be more efficient than + writing zeros manually. */ + i...