From patchwork Mon Apr 15 11:46:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Gao X-Patchwork-Id: 1923698 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=gYaaugGk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=NxoafYNx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VJ54W5Kgyz1yY4 for ; Mon, 15 Apr 2024 21:47:06 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1713181624; h=to : date : message-id : in-reply-to : references : mime-version : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : content-type : content-transfer-encoding : sender : from; bh=uePA90qwA55Tqq3l9ynFj+JYJOQtkixqosycTKzjLwY=; b=gYaaugGkRSqaoEABYMkPJzFn9L7ZY2OgkdU/R+1PLD1kxJxgpWc1155uqeh/dZ9GRVLLY UyU3MZNcd70UUhDq8Iqc22Nwc7Lo4DszG4Iu66oPvLabXg0eA3TVxxrhheiHkA9ywlEDhHx SbDHXOtYAm/Jf90MdJGqdJacJ7CYsgU= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1F5CE3C0F50 for ; Mon, 15 Apr 2024 13:47:04 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 16A913C0F50 for ; Mon, 15 Apr 2024 13:46:59 +0200 (CEST) Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id E1A1C200078 for ; Mon, 15 Apr 2024 13:46:58 +0200 (CEST) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-347aa00e3c8so539580f8f.1 for ; Mon, 15 Apr 2024 04:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1713181618; x=1713786418; darn=lists.linux.it; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I4cHY2MgGxQeeuKIVGIA5+kiQOnxg7UbLeogdmqhvKQ=; b=NxoafYNxbu2+6uWg+O4nLGBMwCCADRxw58GwivwSmSdc5Y41zH+4vD6B/3InOPitko aiyXOXr/SIBJwUCWat+Ye0UytqJNH/mlcyGtZw+TgjVKIaK6Gnz2SQVctR8wsYy3kWCH K2ymCLQVeVnibjVObnQxGQ8SWZ4s2j9ddlYoB4rmvDS/q+yuLZHR6uL4khbVFQzEgEmB dNqLEmzzQs6laPyiFg41Vd+FFW1CEblPruxlsYBvAbbZX2cobZlPuUDkZFjPoi6zBzdR v9h3G64Fboy2rznUQFD8mxUASgNng46JCc3tVqQYm47ZNhJ3Zq4B5a5obFMWbEf5BHZp u7tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713181618; x=1713786418; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I4cHY2MgGxQeeuKIVGIA5+kiQOnxg7UbLeogdmqhvKQ=; b=Z3F/3Yh7ypL4On8yT8plC+ylqBjfimAzkV/zMLSQMNk0aQCxeg0Cp9xwTiopLGZ63w s04qSSbwC7kSOPGL4Q+junok1kWImb75dHWAghG2Fj4JtgFOtwtnxlsJmjesHq+AyQuD /qrCQyGXeCmU6QBStk0447hvl8NcIFJj56Xhnc6r20TyKdtpDGbuyZfQa4Nq5rWwbAtF D1bsMoAU8lSxSlonyGRobZdmDsyLZ51bO4gEbS1poER9zIPAz4ccwGZVToWf65dtdhjr llqIjdtEmIf6w1zA3qyRZst5fQMedaMlgNDi1t5Kx4CO0LxwBUlmXJnA5gtseCsglq73 FpLQ== X-Gm-Message-State: AOJu0Yxp4dQJV7GdnoqtiXK0ksF1ujpFPB8pfAlk7PGjs40Q2M+ji7Gj 1xVsA/RG8EA9yKFc9kVTlxoa/ORu+ocg0EQ5C1h4cwJX/eCK7aBdyIxKtFXiE9+cBgVpwbGfja0 = X-Google-Smtp-Source: AGHT+IF3uzYBrM+eJjMDuSyZHc/zwaw3YwtUs1OnjitgAzPgd9L65+O775fBMtWWd0Gt2GA+0yh5cQ== X-Received: by 2002:a05:6000:1952:b0:347:2b13:bb8 with SMTP id e18-20020a056000195200b003472b130bb8mr7356746wry.0.1713181617668; Mon, 15 Apr 2024 04:46:57 -0700 (PDT) Received: from localhost ([2a07:de40:b240:0:dc1a:df90:dc1a:df90]) by smtp.gmail.com with ESMTPSA id j23-20020a05600c1c1700b0041880a0e8ecsm200111wms.43.2024.04.15.04.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 04:46:57 -0700 (PDT) To: ltp@lists.linux.it Date: Mon, 15 Apr 2024 07:46:52 -0400 Message-Id: <20240415114652.22687-1-wegao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240331021720.9527-1-wegao@suse.com> References: <20240331021720.9527-1-wegao@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4] ioctl_fiemap01: New test for fiemap ioctl() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Wei Gao via ltp From: Wei Gao Reply-To: Wei Gao Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Fixes: #535 Signed-off-by: Wei Gao --- runtest/syscalls | 2 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_fiemap01.c | 110 ++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_fiemap01.c diff --git a/runtest/syscalls b/runtest/syscalls index 6e2407879..4e6ce5aef 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -589,6 +589,8 @@ ioctl_ns07 ioctl_ns07 ioctl_sg01 ioctl_sg01 +ioctl_fiemap01 ioctl_fiemap01 + inotify_init1_01 inotify_init1_01 inotify_init1_02 inotify_init1_02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 5fff7a61d..64adcdfe6 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -22,3 +22,4 @@ /ioctl_ns06 /ioctl_ns07 /ioctl_sg01 +/ioctl_fiemap01 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_fiemap01.c b/testcases/kernel/syscalls/ioctl/ioctl_fiemap01.c new file mode 100644 index 000000000..1b3f80ed9 --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_fiemap01.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Wei Gao + */ + +/*\ + * [Description] + * + * Verify basic fiemap ioctl. + */ + +#include +#include +#include +#include + +#include "tst_test.h" + +#define MNTPOINT "mntpoint" +#define TESTFILE "testfile" +#define NUM_EXTENT 3 + +static void print_extens(struct fiemap *fiemap) +{ + tst_res(TDEBUG, "File extent count: %u", fiemap->fm_mapped_extents); + + for (unsigned int i = 0; i < fiemap->fm_mapped_extents; ++i) { + tst_res(TDEBUG, "Extent %u: Logical offset: %llu, Physical offset: %llu, flags: %u, Length: %llu", + i + 1, + fiemap->fm_extents[i].fe_logical, + fiemap->fm_extents[i].fe_physical, + fiemap->fm_extents[i].fe_flags, + fiemap->fm_extents[i].fe_length); + } +} + +static void check_extent(struct fiemap *fiemap, unsigned int fm_mapped_extents, int index_extents, int fe_flags, unsigned int min_fe_physical, unsigned int fe_length) +{ + TST_EXP_EXPR(fiemap->fm_mapped_extents == fm_mapped_extents, + "Check extent fm_mapped_extents is %d", fm_mapped_extents); + TST_EXP_EXPR(fiemap->fm_extents[index_extents].fe_flags & fe_flags, + "Check fe_flags is %d", fe_flags); + TST_EXP_EXPR(fiemap->fm_extents[index_extents].fe_physical >= min_fe_physical, + "Check fe_physical > %d", min_fe_physical); + TST_EXP_EXPR(fiemap->fm_extents[index_extents].fe_length == fe_length, + "Check fe_length is %d", fe_length); +} + +static void verify_ioctl(void) +{ + int fd; + struct fiemap *fiemap; + struct statvfs fs_info; + unsigned long blk_size; + + SAFE_CHDIR(MNTPOINT); + fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, 0644); + + if (statvfs(".", &fs_info) != 0) + tst_brk(TBROK, "statvfs failed"); + + blk_size = fs_info.f_bsize; + + fiemap = SAFE_MALLOC(sizeof(struct fiemap) + sizeof(struct fiemap_extent) * NUM_EXTENT); + fiemap->fm_start = 0; + fiemap->fm_length = ~0ULL; + fiemap->fm_extent_count = 1; + + fiemap->fm_flags = -1; + TST_EXP_FAIL(ioctl(fd, FS_IOC_FIEMAP, fiemap), EBADR); + + fiemap->fm_flags = 0; + TST_EXP_PASS(ioctl(fd, FS_IOC_FIEMAP, fiemap)); + print_extens(fiemap); + TST_EXP_EXPR(fiemap->fm_mapped_extents == 0, + "Check extent fm_mapped_extents is 0"); + + char *buf = SAFE_MALLOC(blk_size); + + SAFE_WRITE(SAFE_WRITE_ANY, fd, buf, blk_size); + fiemap->fm_flags = FIEMAP_FLAG_SYNC; + TST_EXP_PASS(ioctl(fd, FS_IOC_FIEMAP, fiemap)); + print_extens(fiemap); + check_extent(fiemap, 1, 0, FIEMAP_EXTENT_LAST, 1, blk_size); + + fiemap->fm_extent_count = NUM_EXTENT; + SAFE_LSEEK(fd, 2 * blk_size, SEEK_SET); + SAFE_WRITE(SAFE_WRITE_ALL, fd, buf, blk_size); + SAFE_LSEEK(fd, 4 * blk_size, SEEK_SET); + SAFE_WRITE(SAFE_WRITE_ALL, fd, buf, blk_size); + TST_EXP_PASS(ioctl(fd, FS_IOC_FIEMAP, fiemap)); + print_extens(fiemap); + check_extent(fiemap, NUM_EXTENT, NUM_EXTENT - 1, FIEMAP_EXTENT_LAST, 1, blk_size); + + free(buf); + free(fiemap); + SAFE_CLOSE(fd); + SAFE_UNLINK(TESTFILE); +} + +static struct tst_test test = { + .mount_device = 1, + .mntpoint = MNTPOINT, + .all_filesystems = 1, + .skip_filesystems = (const char *const[]) { + "exfat", "vfat", "ntfs", "tmpfs", NULL + }, + .test_all = verify_ioctl, + .needs_root = 1, +};