Merge branch '2018-04-25-thin-discard-bug'
This commit is contained in:
commit
68284c12a8
@ -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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -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"))))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user