libaal: add device "discard" operation.
v2 cover libaal: add device "discard" operation.
This implements device discard functionality in libaal to be used by mkfs and friends.
Note that the build system is _not_ regenerated, so the direct result of applying these patches won't build.
v2: remove a wrong assertion (result of copy-pasting), fix indentation.
Ivan Shapovalov (2):
configure.in: check for fallocate() and related headers.
Add aal_device_discard() function and implement it for file-based device.
configure.in | 4 +-- include/aal/device.h | 4 +++ include/aal/types.h | 3 +++ src/device.c | 14 ++++++++++ src/file.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.2
RFC PATCH v2 1/2 configure.in: check for fallocate() and related headers.
--- configure.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
configure.in +2 -2
@@ -72,7 +72,7 @@ AC_PROG_CC # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([errno.h fcntl.h stdlib.h string.h sys/ioctl.h unistd.h]) +AC_CHECK_HEADERS([errno.h fcntl.h stdlib.h string.h sys/ioctl.h unistd.h linux/falloc.h linux/types.h]) AC_C_BIGENDIAN
@@ -86,7 +86,7 @@ AC_STRUCT_TM AC_PROG_GCC_TRADITIONAL AC_FUNC_MEMCMP AC_HEADER_STDC -AC_CHECK_FUNCS([memmove memset strchr strerror strpbrk strrchr]) +AC_CHECK_FUNCS([memmove memset strchr strerror strpbrk strrchr fallocate]) # The options -falign-* are supported by gcc 3.0 or later. # Probably it is sufficient to only check for -falign-loops.
Signature · 1 line
1.9.2
RFC PATCH v2 2/2 Add aal_device_discard() function and implement it for file-based device.
In reply to Ivan ShapovalovInternally, ioctl(BLKDISCARD) or fallocate(FALLOC_FL_PUNCH_HOLE) is used depending on whether the file is actually a block device.
--- include/aal/device.h | 4 +++ include/aal/types.h | 3 +++ src/device.c | 14 ++++++++++ src/file.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+)
include/aal/device.h +4 -0
@@ -22,6 +22,10 @@ extern errno_t aal_device_reopen(aal_device_t *device,uint32_t blksize, int flags); +extern errno_t aal_device_discard (aal_device_t *device, +blk_t block, +count_t count); +extern errno_t aal_device_write (aal_device_t *device,void *buff,blk_t block,count_t count);
include/aal/types.h +3 -0
@@ -203,6 +203,9 @@ struct aal_device_ops {errno_t (*write) (aal_device_t *,void *,blk_t ,count_t ); +errno_t (*discard) (aal_device_t *, +blk_t ,count_t ); +errno_t (*sync) (aal_device_t *); errno_t (*equals) (aal_device_t *,
src/device.c +14 -0
@@ -114,6 +114,20 @@ errno_t aal_device_write(return device->ops->write (device, buff, block, count); } +/* Performs discard operation on specified device. Actualqy it calls corresponding +operation (discard) from assosiated with device operations. Returns error code, +see types.h for more detailed description of errno_t. */ +errno_t aal_device_discard ( +aal_device_t *device,/* device instance we will discard */ +blk_t block,/* block we will begin discarding from */ +count_t count)/* number of blocks to be discarded */ +{ +aal_assert ("intelfx-1" , device !=NULL ); + +aal_device_check_routine (device, discard, return -EINVAL ); +return device->ops->discard (device, block, count); +} +/* Performs sync operation on specified device. Actualy it calls corresponding operation (sync) from assosiated with device operations. Returns error code, see types.h for more detailed description of errno_t. */
src/file.c +74 -0
101 lines not on this page · raw message
Signature · 1 line
1.9.2