Merge branch '2018-04-25-thin-discard-bug'

This commit is contained in:
Joe Thornber 2018-06-21 10:11:21 +01:00
commit 68284c12a8
2 changed files with 29 additions and 4 deletions

View File

@ -487,8 +487,6 @@ int dm_load(struct dm_interface *dmi, const char *name,
return r;
}
//----------------------------------------------------------------
// returns false if control buffer too small.
static bool get_status(struct dm_interface *dmi, struct dm_ioctl *ctl,
const char *name, unsigned flags,
int *result)
@ -611,4 +609,24 @@ int get_dev_size(const char *path, uint64_t *sectors)
return r;
}
int discard(const char *path, uint64_t sector_b, uint64_t sector_e)
{
int r, fd;
uint64_t payload[2];
fd = open(path, O_RDWR);
if (fd < 0) {
fprintf(stderr, "couldn't open %s", path);
return -EINVAL;
}
payload[0] = sector_b;
payload[1] = sector_e;
r = ioctl(fd, BLKDISCARD, payload);
close(fd);
return r;
}
//----------------------------------------------------------------

View File

@ -44,7 +44,8 @@
message
get-dev-size)
get-dev-size
discard)
(import (chezscheme)
(disk-units)
@ -393,4 +394,10 @@
(if (zero? r)
(sectors result)
(fail (fmt #f "get-dev-size failed: " r))))))
)
(define (discard dev sb se)
(define c-discard
(foreign-procedure "discard" (string unsigned-64 unsigned-64) int))
(unless (zero? (c-discard dev sb se))
(fail (fmt #f "discard ioctl failed"))))
)