[PATCH] file_ioctl.c: print first two extents for FIDEDUPERANGE in abbrev mode
Jeff Mahoney
jeffm at suse.com
Fri May 27 20:07:22 UTC 2016
* file_ioctl.c (file_ioctl, print_file_dedupe_range_info): print first
two elements of info array in abbrev mode
* tests/btrfs.c (btrfs_test_extent_same_ioctl): handle newly
printed elements
---
file_ioctl.c | 31 +++++++++++++++----------
tests/btrfs.c | 74 ++++++++++++++++++++++++++++++++++++++---------------------
2 files changed, 67 insertions(+), 38 deletions(-)
diff --git a/file_ioctl.c b/file_ioctl.c
index b065db9..95e526d 100644
--- a/file_ioctl.c
+++ b/file_ioctl.c
@@ -80,6 +80,7 @@ print_file_dedupe_range_info(struct tcb *tcp, void *elem_buf,
size_t elem_size, void *data)
{
const struct file_dedupe_range_info *info = elem_buf;
+ int *count = data;
if (entering(tcp)) {
tprints("{dest_fd=");
@@ -91,6 +92,11 @@ print_file_dedupe_range_info(struct tcb *tcp, void *elem_buf,
(uint64_t) info->bytes_deduped, info->status);
}
+ if (count && --*count == 0) {
+ tprints(", ...");
+ return false;
+ }
+
return true;
}
@@ -141,6 +147,10 @@ file_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
case FIDEDUPERANGE: { /* RW */
struct file_dedupe_range args;
+ struct file_dedupe_range_info info;
+ int *limit = NULL;
+ int count = 2;
+ bool rc;
if (entering(tcp))
tprints(", ");
@@ -162,19 +172,16 @@ file_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
(uint16_t) args.dest_count);
}
- bool rc = false;
tprints("info=");
- if (abbrev(tcp)) {
- tprints("...");
- } else {
- struct file_dedupe_range_info info;
- rc = print_array(tcp,
- arg + offsetof(typeof(args), info),
- args.dest_count,
- &info, sizeof(info),
- umoven_or_printaddr,
- print_file_dedupe_range_info, 0);
- }
+
+ /* Limit how many elements we print in abbrev mode */
+ if (abbrev(tcp) && args.dest_count > count)
+ limit = &count;
+
+ rc = print_array(tcp, arg + offsetof(typeof(args), info),
+ args.dest_count, &info, sizeof(info),
+ umoven_or_printaddr,
+ print_file_dedupe_range_info, limit);
tprints("}");
if (!rc || exiting(tcp))
diff --git a/tests/btrfs.c b/tests/btrfs.c
index f1dee55..4014c88 100644
--- a/tests/btrfs.c
+++ b/tests/btrfs.c
@@ -1597,27 +1597,25 @@ btrfs_test_extent_same_ioctl(void)
printf("ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, "
"{src_offset=%" PRIu64
", src_length=%" PRIu64
- ", dest_count=%hu, info=",
+ ", dest_count=%hu, info=[]",
(uint64_t)args.src_offset,
(uint64_t)args.src_length, args.dest_count);
- if (verbose)
- printf("[]");
- else
- printf("...");
ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME, &args);
printf("}) = -1 EBADF (%m)\n");
- argsp = malloc(sizeof(*argsp) + sizeof(argsp->info[0]) * 2);
+ argsp = malloc(sizeof(*argsp) + sizeof(argsp->info[0]) * 3);
if (!argsp)
perror_msg_and_fail("malloc failed");
- memset(argsp, 0, sizeof(*argsp) + sizeof(argsp->info[0]) * 2);
+ memset(argsp, 0, sizeof(*argsp) + sizeof(argsp->info[0]) * 3);
*argsp = args;
- argsp->dest_count = 2;
+ argsp->dest_count = 3;
argsp->info[0].dest_fd = 2;
argsp->info[0].dest_offset = 0;
argsp->info[1].dest_fd = 2;
argsp->info[1].dest_offset = 10240;
+ argsp->info[2].dest_fd = 2;
+ argsp->info[2].dest_offset = 20480;
printf("ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, "
"{src_offset=%" PRIu64
@@ -1625,23 +1623,25 @@ btrfs_test_extent_same_ioctl(void)
", dest_count=%hu, info=",
(int64_t)argsp->src_offset,
(uint64_t)argsp->src_length, argsp->dest_count);
- if (verbose)
printf("[{dest_fd=%" PRId64 ", dest_offset=%" PRIu64
- "}, {dest_fd=%" PRId64 ", dest_offset=%"PRIu64
- "}]",
+ "}, {dest_fd=%" PRId64 ", dest_offset=%"PRIu64 "}",
(int64_t)argsp->info[0].dest_fd,
(uint64_t)argsp->info[0].dest_offset,
(int64_t)argsp->info[1].dest_fd,
(uint64_t)argsp->info[1].dest_offset);
+ if (verbose)
+ printf(", {dest_fd=%" PRId64 ", dest_offset=%" PRIu64 "}",
+ (int64_t)argsp->info[2].dest_fd,
+ (uint64_t)argsp->info[2].dest_offset);
else
- printf("...");
+ printf(", ...");
+ printf("]");
ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME, argsp);
printf("}) = -1 EBADF (%m)\n");
if (write_ok) {
int fd1, fd2;
char buf[16384];
- int size = sizeof(*argsp) + sizeof(argsp->info[0]);
memset(buf, 0, sizeof(buf));
@@ -1655,6 +1655,10 @@ btrfs_test_extent_same_ioctl(void)
if (write(fd1, buf, sizeof(buf)) < 0)
perror_msg_and_fail("write: fd1");
+ if (write(fd1, buf, sizeof(buf)) < 0)
+ perror_msg_and_fail("write: fd1");
+ if (write(fd2, buf, sizeof(buf)) < 0)
+ perror_msg_and_fail("write: fd2");
if (write(fd2, buf, sizeof(buf)) < 0)
perror_msg_and_fail("write: fd2");
@@ -1663,34 +1667,52 @@ btrfs_test_extent_same_ioctl(void)
if (fd2 < 0)
perror_msg_and_fail("open file2 failed");
- argsp = realloc(argsp, size);
- if (!argsp)
- perror_msg_and_fail("realloc failed");
- memset(argsp, 0, size);
+ memset(argsp, 0, sizeof(*argsp) + sizeof(argsp->info[0]) * 3);
argsp->src_offset = 0;
- argsp->src_length = sizeof(buf);
- argsp->dest_count = 1;
+ argsp->src_length = 4096;
+ argsp->dest_count = 3;
argsp->info[0].dest_fd = fd2;
argsp->info[0].dest_offset = 0;
+ argsp->info[1].dest_fd = fd2;
+ argsp->info[1].dest_offset = 10240;
+ argsp->info[2].dest_fd = fd2;
+ argsp->info[2].dest_offset = 20480;
printf("ioctl(%d, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, "
"{src_offset=%" PRIu64 ", src_length=%" PRIu64
", dest_count=%hu, info=", fd1,
(uint64_t)argsp->src_offset,
(uint64_t)argsp->src_length, argsp->dest_count);
+ printf("[{dest_fd=%" PRId64 ", dest_offset=%" PRIu64
+ "}, {dest_fd=%" PRId64 ", dest_offset=%"PRIu64 "}",
+ (int64_t)argsp->info[0].dest_fd,
+ (uint64_t)argsp->info[0].dest_offset,
+ (int64_t)argsp->info[1].dest_fd,
+ (uint64_t)argsp->info[1].dest_offset);
if (verbose)
- printf("[{dest_fd=%d, dest_offset=0}]", fd2);
+ printf(", {dest_fd=%" PRId64
+ ", dest_offset=%" PRIu64 "}",
+ (int64_t)argsp->info[2].dest_fd,
+ (uint64_t)argsp->info[2].dest_offset);
else
- printf("...");
+ printf(", ...");
+
ioctl(fd1, BTRFS_IOC_FILE_EXTENT_SAME, argsp);
- printf("} => {info=");
+ printf("]} => {info=");
+ printf("[{bytes_deduped=%" PRIu64 ", status=%d}, "
+ "{bytes_deduped=%" PRIu64 ", status=%d}",
+ (uint64_t)argsp->info[0].bytes_deduped,
+ argsp->info[0].status,
+ (uint64_t)argsp->info[1].bytes_deduped,
+ argsp->info[1].status);
if (verbose)
- printf("[{bytes_deduped=%u, status=0}]",
- (unsigned) sizeof(buf));
+ printf(", {bytes_deduped=%" PRIu64 ", status=%d}",
+ (uint64_t)argsp->info[2].bytes_deduped,
+ argsp->info[2].status);
else
- printf("...");
- printf("}) = 0\n");
+ printf(", ...");
+ printf("]}) = 0\n");
close(fd1);
close(fd2);
unlinkat(btrfs_test_dir_fd, "file1", 0);
--
2.7.1
--
Jeff Mahoney
SUSE Labs
More information about the Strace-devel
mailing list