search for: is_block_device

Displaying 20 results from an estimated 65 matches for "is_block_device".

2018 Aug 02
2
Re: [PATCH 3/3] file: Zero for block devices on old kernels
..._aligned(struct handle *h, uint64_t n) > +{ > + return n % h->sector_size == 0; Since we know (but the compiler doesn't) that sector_size is a power of 2, it is slightly faster to use bitwise math: return !(n & (h->sector_size - 1)) > +#ifdef BLKSSZGET > + if (h->is_block_device) { > + if (ioctl (h->fd, BLKSSZGET, &h->sector_size)) { > + nbdkit_error ("ioctl(BLKSSZGET): %s: %m", filename); > + free (h); > + return NULL; If the ioctl() fails, would it be better to just fall back... > + } > + } > +#else > +...
2018 Aug 02
0
[PATCH 3/3] file: Zero for block devices on old kernels
...HOLE) #include <linux/falloc.h> /* For FALLOC_FL_*, glibc < 2.18 */ +#include <linux/fs.h> /* For BLKZEROOUT */ #endif #include <nbdkit-plugin.h> @@ -119,16 +120,25 @@ file_config_complete (void) /* The per-connection handle. */ struct handle { int fd; + bool is_block_device; + int sector_size; bool can_punch_hole; bool can_zero_range; bool can_fallocate; }; +static bool +is_aligned(struct handle *h, uint64_t n) +{ + return n % h->sector_size == 0; +} + /* Create the per-connection handle. */ static void * file_open (int readonly) { struct handl...
2018 Aug 19
0
[PATCH v4 4/4] file: Zero for block devices on old kernels
...lude <linux/fs.h> /* For BLKZEROOUT */ +#endif + #include <nbdkit-plugin.h> +#include "isaligned.h" + #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif @@ -119,9 +126,12 @@ file_config_complete (void) /* The per-connection handle. */ struct handle { int fd; + bool is_block_device; + int sector_size; bool can_punch_hole; bool can_zero_range; bool can_fallocate; + bool can_zeroout; }; /* Create the per-connection handle. */ @@ -129,6 +139,7 @@ static void * file_open (int readonly) { struct handle *h; + struct stat statbuf; int flags; h = malloc (...
2018 Aug 03
0
[PATCH v2 4/4] file: Zero for block devices on old kernels
...lude <linux/fs.h> /* For BLKZEROOUT */ +#endif + #include <nbdkit-plugin.h> +#include "isaligned.h" + #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif @@ -119,9 +126,12 @@ file_config_complete (void) /* The per-connection handle. */ struct handle { int fd; + bool is_block_device; + int sector_size; bool can_punch_hole; bool can_zero_range; bool can_fallocate; + bool can_zeroout; }; /* Create the per-connection handle. */ @@ -129,6 +139,7 @@ static void * file_open (int readonly) { struct handle *h; + struct stat statbuf; int flags; h = malloc (...
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
2020 Aug 07
0
[nbdkit PATCH 1/4] file: Forbid non-regular, non-block file names
...ns/file/file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/file/file.c b/plugins/file/file.c index dc99f992..e049864a 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -189,7 +189,16 @@ file_open (int readonly) return NULL; } - h->is_block_device = S_ISBLK (statbuf.st_mode); + if (S_ISBLK (statbuf.st_mode)) + h->is_block_device = true; + else if (S_ISREG (statbuf.st_mode)) + h->is_block_device = false; + else { + nbdkit_error ("file is not regular or block device: %s", filename); + close (h->fd); + free...
2018 Aug 02
0
Re: [PATCH 3/3] file: Zero for block devices on old kernels
...> + return n % h->sector_size == 0; > > Since we know (but the compiler doesn't) that sector_size is a power of > 2, it is slightly faster to use bitwise math: > return !(n & (h->sector_size - 1)) > Right > > > +#ifdef BLKSSZGET > > + if (h->is_block_device) { > > + if (ioctl (h->fd, BLKSSZGET, &h->sector_size)) { > > + nbdkit_error ("ioctl(BLKSSZGET): %s: %m", filename); > > + free (h); > > + return NULL; > > If the ioctl() fails, would it be better to just fall back... > > &gt...
2018 Aug 02
0
[PATCH] file: Zero support for block devices and NFS 4.2
...; #include <linux/falloc.h> /* For FALLOC_FL_* on RHEL, glibc < 2.18 */ +#include <sys/ioctl.h> +#include <linux/fs.h> #include <nbdkit-plugin.h> @@ -116,6 +119,10 @@ file_config_complete (void) /* The per-connection handle. */ struct handle { int fd; + bool is_block_device; + bool can_punch_hole; + bool can_zero_range; + bool can_fallocate; }; /* Create the per-connection handle. */ @@ -123,6 +130,7 @@ static void * file_open (int readonly) { struct handle *h; + struct stat statbuf; int flags; h = malloc (sizeof *h); @@ -144,6 +152,23 @@ file_ope...
2018 Jul 29
3
[PATCH] file: Zero support for block devices and NFS 4.2
...; #include <linux/falloc.h> /* For FALLOC_FL_* on RHEL, glibc < 2.18 */ +#include <sys/ioctl.h> +#include <linux/fs.h> #include <nbdkit-plugin.h> @@ -116,6 +119,10 @@ file_config_complete (void) /* The per-connection handle. */ struct handle { int fd; + bool is_block_device; + bool can_punch_hole; + bool can_zero_range; + bool can_fallocate; }; /* Create the per-connection handle. */ @@ -123,6 +130,7 @@ static void * file_open (int readonly) { struct handle *h; + struct stat statbuf; int flags; h = malloc (sizeof *h); @@ -144,6 +152,23 @@ file_ope...
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
2020 Apr 09
0
[PATCH nbdkit v2 1/3] file: Move file operators to a new common/fileops mini-library.
...#include <unistd.h> +#include <sys/types.h> + +/* Either use this as the per-connection handle, or it must appear as + * the first member of the per-connection handle. Don’t access these + * fields directly from your plugin. + */ +struct fileops { + int fd; + int sector_size; + bool is_block_device; + bool can_punch_hole; + bool can_zero_range; + bool can_fallocate; + bool can_zeroout; +}; + +/* Initialize the fileops struct. ‘fd’ is a file descriptor opened on + * the local file or block device that you want to serve. Call this + * from your .open callback after allocating the handle a...
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 Sep 01
2
[PATCH v2v] v2v: Allow output to block devices (RHBZ#1868690).
...+++ b/v2v/v2v.ml @@ -683,7 +683,10 @@ and copy_targets cmdline targets input output = fun t -> match t.target_file with | TargetURI _ -> () - | TargetFile s -> try unlink s with _ -> () + | TargetFile filename -> + if not (is_block_device filename) then ( + try unlink filename with _ -> () + ) ) targets ) ); @@ -713,27 +716,33 @@ and copy_targets cmdline targets input output = (match t.target_file with | TargetFile filename -> - (* It turns out that libguestfs&...
2020 Feb 10
2
[nbdkit PATCH 05/10] plugins: Wire up file-based plugin support for NBD_INFO_INIT_STATE
...@@ struct handle { bool can_zero_range; bool can_fallocate; bool can_zeroout; + bool can_extents; + bool init_sparse; + bool init_zero; }; /* Create the per-connection handle. */ @@ -214,6 +217,52 @@ file_open (int readonly) h->can_fallocate = true; h->can_zeroout = h->is_block_device; + h->can_extents = false; + h->init_sparse = false; + h->init_zero = false; +#ifdef SEEK_HOLE + if (!h->is_block_device) { + off_t r; + + /* A simple test to see whether SEEK_DATA/SEEK_HOLE are likely to work on + * the current filesystem, and to see if the image is spar...
2020 Feb 11
0
Re: [nbdkit PATCH 05/10] plugins: Wire up file-based plugin support for NBD_INFO_INIT_STATE
On Mon, Feb 10, 2020 at 03:43:58PM -0600, Eric Blake wrote: > @@ -214,6 +217,52 @@ file_open (int readonly) > h->can_fallocate = true; > h->can_zeroout = h->is_block_device; > > + h->can_extents = false; > + h->init_sparse = false; > + h->init_zero = false; > +#ifdef SEEK_HOLE > + if (!h->is_block_device) { > + off_t r; > + > + /* A simple test to see whether SEEK_DATA/SEEK_HOLE are likely to work on > + * the c...
2020 Aug 07
0
[nbdkit PATCH 2/4] file: Add .list_exports support
...1) { + close (fd); + return -1; + } + } + errno = 0; + } + if (errno) { + nbdkit_error ("readdir: %m"); + close (fd); + return -1; + } + close (fd); + return 0; +} + /* The per-connection handle. */ struct handle { + char *file; int fd; bool is_block_device; int sector_size; @@ -170,21 +229,44 @@ file_open (int readonly) return NULL; } + if (directory) { + const char *exportname = nbdkit_export_name (); + + if (strchr (exportname, '/')) { + nbdkit_error ("exportname cannot contain /"); + errno = EINVAL; +...
2019 Jul 04
3
[PATCH] v2v: Allow Windows virtio ISO to be a block device as well as a regular file.
...virtio.ml index 59b0bf493..56c7a6757 100644 --- a/v2v/windows_virtio.ml +++ b/v2v/windows_virtio.ml @@ -338,7 +338,7 @@ and copy_from_virtio_win g inspect srcdir destdir filter missing = ) paths ) ) - else if is_regular_file virtio_win then ( + else if is_regular_file virtio_win || is_block_device virtio_win then ( debug "windows: copy_from_virtio_win: guest tools source ISO %s" virtio_win; try -- 2.22.0
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 ioctl.h will cause
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.
2020 Sep 01
2
Re: [PATCH v2v] v2v: Allow output to block devices (RHBZ#1868690).
...t with "qcow2" -> Some "1.1" | _ -> None in > > - output#disk_create filename t.target_format > > - t.target_overlay.ov_virtual_size > > - ?preallocation ?compat > > + if not (is_block_device filename) then ( > > + (* It turns out that libguestfs's disk creation code is > > + * considerably more flexible and easier to use than > > + * qemu-img, so create the disk explicitly using libguestfs > > + * then pass the...