Displaying 20 results from an estimated 122 matches for "is_aligned".
Did you mean:
__aligned
2018 Sep 17
4
[PATCH nbdkit v2] common: isaligned: Use a macro instead of relying on implicit truncation.
...mon/include/isaligned.h
+++ b/common/include/isaligned.h
@@ -36,16 +36,15 @@
#include <assert.h>
#include <stdbool.h>
+#include <stdint.h>
#include "ispowerof2.h"
/* Return true if size is a multiple of align. align must be power of 2.
*/
-static inline bool
-is_aligned (unsigned int size, unsigned int align)
-{
- assert (is_power_of_2 (align));
- return !(size & (align - 1));
-}
+#define IS_ALIGNED(size, align) ({ \
+ assert (is_power_of_2 ((align))); \
+ !((size) & ((align) - 1)); \
+})
#endif /* NBDKIT_...
2018 Sep 17
0
[PATCH nbdkit v3 1/3] common: isaligned: Use a macro instead of relying on implicit truncation.
...mon/include/isaligned.h
+++ b/common/include/isaligned.h
@@ -36,16 +36,15 @@
#include <assert.h>
#include <stdbool.h>
+#include <stdint.h>
#include "ispowerof2.h"
/* Return true if size is a multiple of align. align must be power of 2.
*/
-static inline bool
-is_aligned (unsigned int size, unsigned int align)
-{
- assert (is_power_of_2 (align));
- return !(size & (align - 1));
-}
+#define IS_ALIGNED(size, align) ({ \
+ assert (is_power_of_2 ((align))); \
+ !((size) & ((align) - 1)); \
+})
#endif /* NBDKIT_...
2018 Sep 17
0
Re: [PATCH nbdkit v2] common: isaligned: Use a macro instead of relying on implicit truncation.
...#include <assert.h>
> #include <stdbool.h>
> +#include <stdint.h>
>
Not need with this change...
>
> #include "ispowerof2.h"
>
> /* Return true if size is a multiple of align. align must be power of 2.
> */
> -static inline bool
> -is_aligned (unsigned int size, unsigned int align)
> -{
> - assert (is_power_of_2 (align));
> - return !(size & (align - 1));
> -}
> +#define IS_ALIGNED(size, align) ({ \
> + assert (is_power_of_2 ((align))); \
> + !((size) & ((align) - 1));...
2018 Aug 02
2
Re: [PATCH 3/3] file: Zero for block devices on old kernels
...< 2.18 */
> +#include <linux/fs.h> /* For BLKZEROOUT */
Will this pick up BLKZEROOUT in all cases where it is needed? Or do we
need to relax the !defined(FALLOC_FL_PUNCH_HOLE), and just blindly
include both of these headers for all Linux compilations?
> +static bool
> +is_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...
2018 Sep 17
2
Re: [PATCH nbdkit v2] common: isaligned: Use a macro instead of relying on implicit truncation.
On 9/17/18 3:39 PM, Nir Soffer wrote:
>> +#define IS_ALIGNED(size, align) ({ \
>> + assert (is_power_of_2 ((align))); \
>> + !((size) & ((align) - 1)); \
>> +})
>>
>
> But this version will happily accept singed int, and I think this code
> behavior with signed int is undefin...
2018 Sep 17
1
Re: [PATCH nbdkit v2] common: isaligned: Use a macro instead of relying on implicit truncation.
On 9/17/18 4:41 PM, Nir Soffer wrote:
> The FreeBSD version:
>
> #define IS_ALIGNED <http://fxr.watson.org/fxr/ident?i=IS_ALIGNED>(n
> <http://fxr.watson.org/fxr/ident?i=n>,align) (!((uint32_t)(n
> <http://fxr.watson.org/fxr/ident?i=n>) & (align - 1)))
>
> http://fxr.watson.org/fxr/source/contrib/ncsw/inc/ncsw_ext.h#L182
Which truncates to 3...
2018 Aug 02
0
Re: [PATCH 3/3] file: Zero for block devices on old kernels
...ck up BLKZEROOUT in all cases where it is needed? Or do we
> need to relax the !defined(FALLOC_FL_PUNCH_HOLE), and just blindly
> include both of these headers for all Linux compilations?
>
It works on RHEL 7.5, but it should not depend on FALLOC_FL_*.
> > +static bool
> > +is_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))
>
Right
>
>...
2020 Jul 08
1
Re: [nbdkit PATCH 2/3] extents: Add nbdkit_extents_aligned()
...nbdkit_backend *nxdata,
> + uint32_t count, uint64_t offset,
> + uint32_t flags, uint32_t align,
> + struct nbdkit_extents *exts, int *err)
> +{
> + size_t i;
> + struct nbdkit_extent e, e2;
> +
> + if (!IS_ALIGNED(count | offset, align)) {
> + nbdkit_error ("nbdkit_extents_aligned: unaligned request");
> + *err = EINVAL;
> + return -1;
> + }
I wonder if this also should be an assert? This is less clear to me
than the vector case however.
> + /* Perform an initial query,...
2018 Sep 17
3
Re: [PATCH nbdkit 1/3] common: isaligned: Use uint64_t instead of unsigned int.
....h
> @@ -36,13 +36,14 @@
>
> #include <assert.h>
> #include <stdbool.h>
> +#include <stdint.h>
>
> #include "ispowerof2.h"
>
> /* Return true if size is a multiple of align. align must be power of 2.
> */
> static inline bool
> -is_aligned (unsigned int size, unsigned int align)
> +is_aligned (uint64_t size, unsigned int align)
> {
> assert (is_power_of_2 (align));
> return !(size & (align - 1));
> --
> 2.19.0.rc0
>
> _______________________________________________
> Libguestfs mailing list
>...
2018 Sep 17
7
[PATCH nbdkit v3 0/3] Add partitioning plugin.
The partitioning plugin patch is the same (except for rebasing).
However I have changed the first two patches based on feedback
received. In particular this fixes a very serious bug found by Eric
Blake in the current truncate filter.
Rich.
2018 Aug 13
1
Re: [PATCH v2 3/4] common: Add isaligned helper module
On 08/03/2018 02:28 PM, Nir Soffer wrote:
> is_aligned (size, align) returns true if size is aligned to align,
> assuming that align is power of 2.
>
> Suggested by Eric in
> https://www.redhat.com/archives/libguestfs/2018-August/msg00036.html
> ---
> common/include/isaligned.h | 50 ++++++++++++++++++++++++++++++++++++++
> 1 f...
2018 Sep 17
0
Re: [PATCH nbdkit v2] common: isaligned: Use a macro instead of relying on implicit truncation.
On Tue, Sep 18, 2018 at 12:13 AM Eric Blake <eblake@redhat.com> wrote:
> On 9/17/18 3:39 PM, Nir Soffer wrote:
>
> >> +#define IS_ALIGNED(size, align) ({ \
> >> + assert (is_power_of_2 ((align))); \
> >> + !((size) & ((align) - 1)); \
> >> +})
> >>
> >
> > But this version will happily accept singed int, and I think this code
> > b...
2018 Aug 19
1
Re: [PATCH v3 3/4] common: Add isaligned helper module
On Sun, Aug 19, 2018 at 01:13:07AM +0300, Nir Soffer wrote:
> is_aligned (size, align) returns true if size is aligned to align,
> assuming that align is power of 2.
>
> Suggested by Eric Blake in
> https://www.redhat.com/archives/libguestfs/2018-August/msg00036.html
> ---
> common/include/isaligned.h | 51 ++++++++++++++++++++++++++++++++++++++
>...
2018 Aug 02
0
[PATCH 3/3] file: Zero for block devices on old kernels
...OOUT */
#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 handle *h;
+ struct stat statbuf;
int flags;
h = malloc (sizeof *h);
@@ -150,6 +160,26 @@ file_open (int readonly)...
2020 Apr 15
0
[PATCH nbdkit 4/9] common/regions: Use new vector type to store the list of regions.
...return 0;
}
static int
-append_padding (struct regions *regions, uint64_t alignment)
+append_padding (regions *rs, uint64_t alignment)
{
struct region region;
assert (is_power_of_2 (alignment));
- region.start = virtual_size (regions);
+ region.start = virtual_size (rs);
if (IS_ALIGNED (region.start, alignment))
return 0; /* nothing to do */
region.end = (region.start & ~(alignment-1)) + alignment - 1;
region.len = region.end - region.start + 1;
region.type = region_zero;
region.description = "padding";
- return append_one_region...
2019 May 11
2
[nbdkit PATCH] cache: Reduce use of bounce-buffer
..._MODEL_PARALLEL
@@ -233,11 +234,13 @@ cache_pread (struct nbdkit_next_ops *next_ops, void *nxdata,
CLEANUP_FREE uint8_t *block = NULL;
assert (!flags);
- block = malloc (blksize);
- if (block == NULL) {
- *err = errno;
- nbdkit_error ("malloc: %m");
- return -1;
+ if (!IS_ALIGNED (count | offset, blksize)) {
+ block = malloc (blksize);
+ if (block == NULL) {
+ *err = errno;
+ nbdkit_error ("malloc: %m");
+ return -1;
+ }
}
/* XXX This breaks up large read requests into smaller ones, which
@@ -258,12 +261,14 @@ cache_pread (struct nbd...
2020 Jul 07
6
[RFC nbdkit PATCH 0/3] aligned .extents
Ultimately, both the blocksize and swab filters want to return aligned
extents to the client. I'm posting this as a snapshot of my work in
progress on how I plan to get there (it's not quite working yet, but
I'm done for today and wanted to at least document my ideas).
I might also add a convenience function for nbdkit_extents_offset,
since we have a number of filters that repeat the
2012 Jan 30
3
[PATCH] Btrfs: allow cloning ranges within the same file
...d(&src->i_mutex, I_MUTEX_PARENT);
mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD);
+ } else {
+ mutex_lock(&inode->i_mutex);
}
/* determine range to clone */
@@ -2302,6 +2300,13 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
!IS_ALIGNED(destoff, bs))
goto out_unlock;
+ /*
+ * allow ranges within the same file to be cloned only if
+ * they don''t overlap
+ */
+ if (src == inode && !(off + len <= destoff || destoff + len <= off))
+ goto out_unlock;
+
if (destoff > inode->i_size) {
ret = btrf...
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 grief on BSD compilation:
ht...
2017 Dec 01
0
[PATCH v18 05/10] xbitmap: add more operations
..._inline void bitmap_clear(unsigned long *map,
>> + unsigned int start,
>> + unsigned int nbits)
>> +{
>> + if (__builtin_constant_p(nbits) && nbits == 1)
>> + __clear_bit(start, map);
>> + else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
>> + __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
> It looks strange to apply __builtin_constant_p test to variables after "& 7".
>
I think this is normal - if the variables are known at compile time, the
calculation will be...