Skip to contentSkip to conversation

libaal: add device "discard" operation.

RFC PATCH Superseded Ivan Shapovalov 2 participants 4 messages May 8, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

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         | 15 +++++++++++
 src/file.c           | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 98 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.2
#1 lore raw

RFC PATCH 1/2 configure.in: check for fallocate() and related headers.

---
 configure.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure.in +2 -2
index 69bc954..470c728 100644
@@ -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
#2 lore raw

RFC PATCH 2/2 Add aal_device_discard() function and implement it for file-based device.

In reply to Ivan Shapovalov

Internally, 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         | 15 +++++++++++
 src/file.c           | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+)
include/aal/device.h +4 -0
index 535fb79..c1ea19d 100644
@@ -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
index e26edda..1dd8fce 100644
@@ -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 +15 -0
index fe0a539..43edd1d 100644
@@ -114,6 +114,21 @@ 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_assert("intelfx-2", buff != 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
#3 lore raw
In reply to Ivan Shapovalov

Great, thank you!

To our shame, reiser4 neither preallocates, nor punches holes. TBH, too lazy ;) I prefer to concentrate on features, which are either unique, or perform better in reiser4 (like discard)...

Thanks,
Edward.

Quoted 18 lines · Ivan Shapovalov

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.

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         | 15 +++++++++++
  src/file.c           | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  5 files changed, 98 insertions(+), 2 deletions(-)