search for: file_get_size

Displaying 20 results from an estimated 31 matches for "file_get_size".

Did you mean: _file_set_size
2018 Jan 31
1
[nbdkit PATCH] file: Add trim support
...fe4191..081848b 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 2013 Red Hat Inc. + * Copyright (C) 2013-2018 Red Hat Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -175,6 +175,18 @@ file_get_size (void *handle) return statbuf.st_size; } +static int +file_can_trim (void *handle) +{ + /* Trim is advisory, but we prefer to advertise it only when we can + * actually (attempt to) punch holes. */ +#ifdef FALLOC_FL_PUNCH_HOLE + return 1; +#else + return 0; +#endif +} + /* Read data fro...
2019 Jan 05
0
[PATCH nbdkit v2 08/11] file: Return NBD_FLAG_CAN_MULTI_CONN for the file plugin.
...ming flush/FUA has been implemented correctly in the previous commit. --- plugins/file/file.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/file/file.c b/plugins/file/file.c index dcff0ee..628f8fb 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -250,6 +250,13 @@ file_get_size (void *handle) } } +/* Allow multiple parallel connections from a single client. */ +static int +file_can_multi_conn (void *handle) +{ + return 1; +} + static int file_can_trim (void *handle) { @@ -507,6 +514,7 @@ static struct nbdkit_plugin plugin = { .open = file_open,...
2019 Mar 20
0
[PATCH nbdkit 8/8] file: Implement extents.
...ze is not the true size. */ +static int64_t +block_device_size (int fd) +{ + off_t size; + + size = lseek (fd, 0, SEEK_END); + if (size == -1) { + nbdkit_error ("lseek (to find device size): %m"); + return -1; + } + + return size; +} + /* Get the file size. */ static int64_t file_get_size (void *handle) @@ -227,15 +249,11 @@ file_get_size (void *handle) struct handle *h = handle; if (h->is_block_device) { - /* Block device, so st_size will not be the true size. */ - off_t size; - - size = lseek (h->fd, 0, SEEK_END); - if (size == -1) { - nbdkit_error (...
2019 Mar 28
0
[PATCH nbdkit v5 FINAL 15/19] file: Implement extents.
...grabs the lseek_lock. + */ +static int64_t +block_device_size (int fd) +{ + off_t size; + + size = lseek (fd, 0, SEEK_END); + if (size == -1) { + nbdkit_error ("lseek (to find device size): %m"); + return -1; + } + + return size; +} + /* Get the file size. */ static int64_t file_get_size (void *handle) @@ -227,15 +251,11 @@ file_get_size (void *handle) struct handle *h = handle; if (h->is_block_device) { - /* Block device, so st_size will not be the true size. */ - off_t size; - - size = lseek (h->fd, 0, SEEK_END); - if (size == -1) { - nbdkit_error (...
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
2018 Aug 02
2
Re: [PATCH 1/3] file: Avoid unsupported fallocate() calls
...indeterminate, whereas the absence results in known to fail. > +#endif > + > +#ifdef FALLOC_FL_ZERO_RANGE > + h->can_zero_range = true; > +#else > + h->can_zero_range = false; Likewise. > +#endif > + > return h; > } > > @@ -189,19 +204,15 @@ file_get_size (void *handle) > return statbuf.st_size; > } > > +/* Trim is advisory, but we prefer to advertise it only when we can actually > + * (attempt to) punch holes. Before we tried to punch a hole, report true if > + * FALLOC_FL_PUNCH_HOLE is defined before we did the first cal...
2019 Jan 05
0
[PATCH nbdkit v2 07/11] file: Implement NBDKIT_API_VERSION 2.
...rim (void *handle, uint32_t count, uint64_t offset) } #endif + if ((flags & NBDKIT_FLAG_FUA) && file_flush (handle, 0) == -1) + return -1; + return 0; } @@ -487,6 +508,7 @@ static struct nbdkit_plugin plugin = { .close = file_close, .get_size = file_get_size, .can_trim = file_can_trim, + .can_fua = file_can_fua, .pread = file_pread, .pwrite = file_pwrite, .flush = file_flush, -- 2.19.2
2020 Aug 07
0
[nbdkit PATCH 2/4] file: Add .list_exports support
...free (h); } @@ -239,7 +323,7 @@ file_close (void *handle) #define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL /* For block devices, stat->st_size is not the true size. The caller - * grabs the lseek_lock. + * grabs the lock. */ static int64_t block_device_size (int fd) @@ -262,7 +346,7 @@ file_get_size (void *handle) struct handle *h = handle; if (h->is_block_device) { - ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lseek_lock); + ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock); return block_device_size (h->fd); } else { /* Regular file. */ @@ -554,7 +638,7 @@ file_can_extents (...
2018 Aug 02
0
[PATCH 3/3] file: Zero for block devices on old kernels
...r_size)) { + nbdkit_error ("ioctl(BLKSSZGET): %s: %m", filename); + free (h); + return NULL; + } + } +#else + h->sector_size = 4096; /* Safe guess */ +#endif + #ifdef FALLOC_FL_PUNCH_HOLE h->can_punch_hole = true; #else @@ -184,27 +214,29 @@ static int64_t file_get_size (void *handle) { struct handle *h = handle; - struct stat statbuf; - if (fstat (h->fd, &statbuf) == -1) { - nbdkit_error ("stat: %m"); - return -1; - } - - if (S_ISBLK (statbuf.st_mode)) { + if (h->is_block_device) { + /* Block device, so st_size will not be...
2018 Aug 02
0
[PATCH 1/3] file: Avoid unsupported fallocate() calls
...nt readonly) return NULL; } +#ifdef FALLOC_FL_PUNCH_HOLE + h->can_punch_hole = true; +#else + h->can_punch_hole = false; +#endif + +#ifdef FALLOC_FL_ZERO_RANGE + h->can_zero_range = true; +#else + h->can_zero_range = false; +#endif + return h; } @@ -189,19 +204,15 @@ file_get_size (void *handle) return statbuf.st_size; } +/* Trim is advisory, but we prefer to advertise it only when we can actually + * (attempt to) punch holes. Before we tried to punch a hole, report true if + * FALLOC_FL_PUNCH_HOLE is defined before we did the first call. Once we tried + * to punch a h...
2018 Aug 19
0
[PATCH v4 4/4] file: Zero for block devices on old kernels
...ze: %s: %m", filename); + } +#endif + #ifdef FALLOC_FL_PUNCH_HOLE h->can_punch_hole = true; #else @@ -163,6 +190,7 @@ file_open (int readonly) #endif h->can_fallocate = true; + h->can_zeroout = h->is_block_device; return h; } @@ -184,27 +212,29 @@ static int64_t file_get_size (void *handle) { struct handle *h = handle; - struct stat statbuf; - if (fstat (h->fd, &statbuf) == -1) { - nbdkit_error ("stat: %m"); - return -1; - } - - if (S_ISBLK (statbuf.st_mode)) { + if (h->is_block_device) { + /* Block device, so st_size will not be...
2018 Aug 03
0
[PATCH v2 4/4] file: Zero for block devices on old kernels
...ze: %s: %m", filename); + } +#endif + #ifdef FALLOC_FL_PUNCH_HOLE h->can_punch_hole = true; #else @@ -163,6 +190,7 @@ file_open (int readonly) #endif h->can_fallocate = true; + h->can_zeroout = h->is_block_device; return h; } @@ -184,27 +212,29 @@ static int64_t file_get_size (void *handle) { struct handle *h = handle; - struct stat statbuf; - if (fstat (h->fd, &statbuf) == -1) { - nbdkit_error ("stat: %m"); - return -1; - } - - if (S_ISBLK (statbuf.st_mode)) { + if (h->is_block_device) { + /* Block device, so st_size will not be...
2018 Aug 02
0
Re: [PATCH 1/3] file: Avoid unsupported fallocate() calls
...gt; +#endif > > + > > +#ifdef FALLOC_FL_ZERO_RANGE > > + h->can_zero_range = true; > > +#else > > + h->can_zero_range = false; > > Likewise. > > > +#endif > > + > > return h; > > } > > > > @@ -189,19 +204,15 @@ file_get_size (void *handle) > > return statbuf.st_size; > > } > > > > +/* Trim is advisory, but we prefer to advertise it only when we can > actually > > + * (attempt to) punch holes. Before we tried to punch a hole, report > true if > > + * FALLOC_FL_PUNCH_HOLE i...
2018 Aug 02
0
[PATCH] file: Zero support for block devices and NFS 4.2
...; + + /* These flags will disabled if an operation is not supported. */ +#ifdef FALLOC_FL_PUNCH_HOLE + h->can_punch_hole = true; +#endif +#ifdef FALLOC_FL_ZERO_RANGE + h->can_zero_range = true; +#endif + h->can_fallocate = true; + return h; } @@ -164,27 +189,29 @@ static int64_t file_get_size (void *handle) { struct handle *h = handle; - struct stat statbuf; - if (fstat (h->fd, &statbuf) == -1) { - nbdkit_error ("stat: %m"); - return -1; - } - - if (S_ISBLK (statbuf.st_mode)) { + if (h->is_block_device) { + /* Block device, so st_size will not be...
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
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]
2019 Apr 23
0
[nbdkit PATCH 4/4] plugins: Utilize ACQUIRE_LOCK_FOR_CURRENT_SCOPE
...{ diff --git a/plugins/file/file.c b/plugins/file/file.c index 2785399..ebfb71d 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -58,6 +58,7 @@ #include <nbdkit-plugin.h> +#include "cleanup.h" #include "isaligned.h" #ifndef O_CLOEXEC @@ -250,12 +251,8 @@ file_get_size (void *handle) struct handle *h = handle; if (h->is_block_device) { - int64_t size; - - pthread_mutex_lock (&lseek_lock); - size = block_device_size (h->fd); - pthread_mutex_unlock (&lseek_lock); - return size; + ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lseek_lock...
2020 Apr 09
0
[PATCH nbdkit v2 1/3] file: Move file operators to a new common/fileops mini-library.
...grabs the lseek_lock. - */ -static int64_t -block_device_size (int fd) -{ - off_t size; - - size = lseek (fd, 0, SEEK_END); - if (size == -1) { - nbdkit_error ("lseek (to find device size): %m"); - return -1; - } - - return size; -} - -/* Get the file size. */ -static int64_t -file_get_size (void *handle) -{ - struct handle *h = handle; - - if (h->is_block_device) { - ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lseek_lock); - return block_device_size (h->fd); - } else { - /* Regular file. */ - struct stat statbuf; - - if (fstat (h->fd, &statbuf) == -1) { -...
2020 Apr 09
1
[PATCH nbdkit PRELIMINARY] file: Move file operators to a new fileops mini-library
There's a lot of code in nbdkit-file-plugin which it would be nice to reuse elsewhere. One possible approach (as outlined here) is simply to move the file callbacks (like file.pread, file.pwrite, file.zero etc) to a new mini-library. They can then be consumed by other plugins fairly easily by doing: static void * foo_open (int readonly) { struct fileops *fops; int fd, flags; /*
2020 Apr 09
6
[PATCH nbdkit v2 0/3] Implement fileops.
Needs some work still, see in particular the commit message for patch 3. Rich.