Skip to content

Commit

Permalink
Added support for thin provision for block device LUNs
Browse files Browse the repository at this point in the history
Enabled thin-provision option for discarding ranges from block devices, that supporting discard.
If file is a block device, UNMAP command don't try a PUNCH HOLE in device, now it call ioctl BLKDISCARD.
  • Loading branch information
borex99 authored Nov 6, 2023
1 parent 4c13f04 commit 4ee260c
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions usr/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,8 @@ void concat_buf_release(struct concat_buf *b);
*/
static inline int unmap_file_region(int fd, off_t offset, off_t length)
{
int err;
struct stat64 st;
#ifdef BLKDISCARD
uint64_t range[2];
#endif

err = fstat64(fd, &st);
if (err < 0)
if (fstat64(fd, &st) < 0)
return -1;
if (S_ISREG(st.st_mode)) {
#ifdef FALLOC_FL_PUNCH_HOLE
Expand All @@ -234,8 +228,7 @@ static inline int unmap_file_region(int fd, off_t offset, off_t length)
#endif
} else if (S_ISBLK(st.st_mode)) {
#ifdef BLKDISCARD
range[0] = offset;
range[1] = length;
uint64_t range[] = { offset, length };
if (ioctl(fd, BLKDISCARD, &range) == 0)
return 0;
#endif
Expand Down

0 comments on commit 4ee260c

Please sign in to comment.