Last active
November 29, 2024 00:48
-
-
Save teknoraver/a8f82ff52fb2a25279f5081939d49f2a to your computer and use it in GitHub Desktop.
test block size of FICLONERANGE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <linux/fs.h> | |
#include <sys/ioctl.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
int setup_src(const char *path, size_t size) | |
{ | |
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); | |
if (fd < 0) | |
return fd; | |
char *buf = malloc(size); | |
if (!buf) | |
return 1; | |
if (write(fd, buf, size) != size) | |
return 1; | |
close(fd); | |
return 0; | |
} | |
int main(int argc, char *argv[]) { | |
if (argc != 3) | |
return 1; | |
struct file_clone_range fcr = { | |
.src_length = sysconf(_SC_PAGESIZE), | |
}; | |
int ret; | |
if (setup_src(argv[1], 1024 * 1024)) | |
return 1; | |
printf("page: %lluK\n", fcr.src_length / 1024); | |
fcr.src_fd = open(argv[1], O_RDONLY); | |
if (fcr.src_fd < 0) | |
return 1; | |
for (; fcr.src_length > 0; fcr.src_length /= 2) { | |
int fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644); | |
if (fd < 0) | |
return 1; | |
printf("Trying block size %lluK.. ", fcr.src_length); | |
ret = ioctl(fd, FICLONERANGE, &fcr); | |
if (!ret) { | |
puts("OK"); | |
} else { | |
printf("errno = %d\n", errno); | |
return 1; | |
} | |
close(fd); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mkdir fs | |
fallocate -l 512M xfs | |
try() { | |
echo "Creating FS with block size of $1" | |
mkfs.xfs -qf xfs -b size=$1 && | |
sudo mount -oloop xfs fs && | |
sudo chmod 777 fs && | |
./testalign fs/src fs/dst | |
sudo umount xfs | |
} | |
size=65536 | |
while [ $size -ge 512 ]; do | |
try $size | |
size=$((size/2)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment