/* EXT4 delalloc reservation leakage testcase * To make that leackage more verbose please apply following patch * http://download.openvz.org/~dmonakhov/junk/ext4-sanity-check.patch */ #include #include #include #include int main(int argc, char **argv) { loff_t len, offset; int fd, ret; char buf[81920]; if (argc != 2) { printf("Usage: %s \n", argv[0]); return 1; } fd = open(argv[1], O_CREAT|O_RDWR, 0777); ftruncate(fd, 40960); fsync(fd); ret = pwrite(fd, buf, 4096, 0); if (ret != 4096) { perror("write failed"); return 1; } /* Leve one page gap between dirty pages */ ret = pwrite(fd, buf, 8192, 8192); if (ret != 8192) { perror("write failed"); return 1; } /* Create uninitialized extent */ ret = fallocate(fd, 0x1, 0, 4096*5); if (ret) { perror("fallocate failed"); return 1; } /* Force block allocation. * Uninitialized extent will be converted to initialized one * during ext4_map_blocks() on writing first pages set. * Later second pages set will discover what blocks are already * initialized, so reservation for that pages will leak. */ fsync(fd); return 0; }