Skip to content

Commit d2a0a61

Browse files
fdanis-ossrichardweinberger
authored andcommitted
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>
1 parent b35507a commit d2a0a61

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

arch/um/drivers/ubd_kern.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,19 @@ static void do_io(struct io_thread_req *req, struct io_desc *desc)
15261526
}
15271527
break;
15281528
case REQ_OP_DISCARD:
1529-
case REQ_OP_WRITE_ZEROES:
15301529
n = os_falloc_punch(req->fds[bit], off, len);
15311530
if (n) {
15321531
req->error = map_error(-n);
15331532
return;
15341533
}
15351534
break;
1535+
case REQ_OP_WRITE_ZEROES:
1536+
n = os_falloc_zeroes(req->fds[bit], off, len);
1537+
if (n) {
1538+
req->error = map_error(-n);
1539+
return;
1540+
}
1541+
break;
15361542
default:
15371543
WARN_ON_ONCE(1);
15381544
req->error = BLK_STS_NOTSUPP;

arch/um/include/shared/os.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ extern unsigned os_major(unsigned long long dev);
168168
extern unsigned os_minor(unsigned long long dev);
169169
extern unsigned long long os_makedev(unsigned major, unsigned minor);
170170
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);
171172
extern int os_eventfd(unsigned int initval, int flags);
172173
extern int os_sendmsg_fds(int fd, const void *buf, unsigned int len,
173174
const int *fds, unsigned int fds_num);

arch/um/os-Linux/file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,15 @@ int os_falloc_punch(int fd, unsigned long long offset, int len)
625625
return n;
626626
}
627627

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+
628637
int os_eventfd(unsigned int initval, int flags)
629638
{
630639
int fd = eventfd(initval, flags);

0 commit comments

Comments
 (0)