Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

um: Fix WRITE_ZEROES in the UBD Driver

Call to fallocate with FALLOC_FL_PUNCH_HOLE on a device backed by a sparse
file can end up by missing data, zeroes data range, if the underlying file
is used with a tool like bmaptool which will referenced only used spaces.

Signed-off-by: Frédéric Danis <frederic.danis@collabora.com>
Acked-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Frédéric Danis and committed by
Richard Weinberger
d2a0a616 b35507a4

+17 -1
+7 -1
arch/um/drivers/ubd_kern.c
··· 1526 1526 } 1527 1527 break; 1528 1528 case REQ_OP_DISCARD: 1529 - case REQ_OP_WRITE_ZEROES: 1530 1529 n = os_falloc_punch(req->fds[bit], off, len); 1530 + if (n) { 1531 + req->error = map_error(-n); 1532 + return; 1533 + } 1534 + break; 1535 + case REQ_OP_WRITE_ZEROES: 1536 + n = os_falloc_zeroes(req->fds[bit], off, len); 1531 1537 if (n) { 1532 1538 req->error = map_error(-n); 1533 1539 return;
+1
arch/um/include/shared/os.h
··· 168 168 extern unsigned os_minor(unsigned long long dev); 169 169 extern unsigned long long os_makedev(unsigned major, unsigned minor); 170 170 extern int os_falloc_punch(int fd, unsigned long long offset, int count); 171 + extern int os_falloc_zeroes(int fd, unsigned long long offset, int count); 171 172 extern int os_eventfd(unsigned int initval, int flags); 172 173 extern int os_sendmsg_fds(int fd, const void *buf, unsigned int len, 173 174 const int *fds, unsigned int fds_num);
+9
arch/um/os-Linux/file.c
··· 625 625 return n; 626 626 } 627 627 628 + int os_falloc_zeroes(int fd, unsigned long long offset, int len) 629 + { 630 + int n = fallocate(fd, FALLOC_FL_ZERO_RANGE|FALLOC_FL_KEEP_SIZE, offset, len); 631 + 632 + if (n < 0) 633 + return -errno; 634 + return n; 635 + } 636 + 628 637 int os_eventfd(unsigned int initval, int flags) 629 638 { 630 639 int fd = eventfd(initval, flags);