From patchwork Mon Mar 3 12:43:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 869986 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0F7D20E332 for ; Mon, 3 Mar 2025 12:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005830; cv=none; b=hZoyNrncIE/tiKnxIqyQ37tSbO35BR3yLZmPRkxZH0Yiu9m2RapbgTCzzIhS8n19W+XlEpLbYWSumnoCVZ70Apq+z5OJq5+0sdT5XKlec+fgqqJCACD+Q4sQ1dNka9SZmtUDesMwy3aAie1L9HAOjf3o/CNsIfufkvaPjxeXWlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005830; c=relaxed/simple; bh=R/UbvFQKhkE48f7V8KwpGE3Rvfnp+1NUFq5fmOTIqUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sCRjYqVDSTfxMY6IUIzCWXKNLcdhjM0sHlAFbPcvU8LygiwOqEekZMPg0L6VrulpYKxBl8ALlKxTQRCUF4HovmHdrJHHnStJ4j0TQ0OhBdf42UgPFMVQlIRmAC9O3l3icLJbXIP5RWxhQ+XXkf4Asa4ZS4bP9ussIXkvkMGg2c0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IYXKli66; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IYXKli66" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741005827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NJxJXtg79V4txmYV9tJrHZcZ/bDrEyIKMG5SvuG1GoQ=; b=IYXKli66hLiyy/0qBX45tpXlft5ZkDz9tYLkh7UvzDq5pGtgUspXYA4G0YU8w2yzx7y3lk xsseYVHWJLooiP9611KjhMZ8GUBcoPwxSghi8OHiCJaK1l9joJ5AqHpaNjrf1/mwc8pKRn jOXp2+1M+9gMyBSM6V11WE1rhN3lav8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-0WjyWbN-PU2fv6HMQHDRQg-1; Mon, 03 Mar 2025 07:43:44 -0500 X-MC-Unique: 0WjyWbN-PU2fv6HMQHDRQg-1 X-Mimecast-MFC-AGG-ID: 0WjyWbN-PU2fv6HMQHDRQg_1741005823 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4DE40190ECCB; Mon, 3 Mar 2025 12:43:43 +0000 (UTC) Received: from localhost (unknown [10.72.120.23]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ED7961956094; Mon, 3 Mar 2025 12:43:41 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Ming Lei Subject: [PATCH 01/11] selftests: ublk: make ublk_stop_io_daemon() more reliable Date: Mon, 3 Mar 2025 20:43:11 +0800 Message-ID: <20250303124324.3563605-2-ming.lei@redhat.com> In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com> References: <20250303124324.3563605-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Improve ublk_stop_io_daemon() in the following ways: - don't wait if ->ublksrv_pid becomes -1, which means that the disk has been stopped - don't wait if ublk char device doesn't exist any more, so we can avoid to rely on inoitfy for wait until the char device is closed And this way may reduce time of delete command a lot. Signed-off-by: Ming Lei --- tools/testing/selftests/ublk/kublk.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c index b65bdaf7e281..2072d880fdc4 100644 --- a/tools/testing/selftests/ublk/kublk.c +++ b/tools/testing/selftests/ublk/kublk.c @@ -691,13 +691,14 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev) return ret; } -static int wait_ublk_dev(char *dev_name, int evt_mask, unsigned timeout) +static int wait_ublk_dev(const char *path, int evt_mask, unsigned timeout) { #define EV_SIZE (sizeof(struct inotify_event)) #define EV_BUF_LEN (128 * (EV_SIZE + 16)) struct pollfd pfd; int fd, wd; int ret = -EINVAL; + const char *dev_name = basename(path); fd = inotify_init(); if (fd < 0) { @@ -761,18 +762,23 @@ static int ublk_stop_io_daemon(const struct ublk_dev *dev) char ublkc[64]; int ret = 0; + if (daemon_pid < 0) + return 0; + /* daemon may be dead already */ if (kill(daemon_pid, 0) < 0) goto wait; - /* - * Wait until ublk char device is closed, when our daemon is shutdown - */ - snprintf(ublkc, sizeof(ublkc), "%s%d", "ublkc", dev_id); - ret = wait_ublk_dev(ublkc, IN_CLOSE_WRITE, 10); - /* double check and inotify may not be 100% reliable */ + snprintf(ublkc, sizeof(ublkc), "/dev/%s%d", "ublkc", dev_id); + + /* ublk char device may be gone already */ + if (access(ublkc, F_OK) != 0) + goto wait; + + /* Wait until ublk char device is closed, when the daemon is shutdown */ + ret = wait_ublk_dev(ublkc, IN_CLOSE, 10); + /* double check and since it may be closed before starting inotify */ if (ret == -ETIMEDOUT) - /* the daemon doesn't exist now if kill(0) fails */ ret = kill(daemon_pid, 0) < 0; wait: waitpid(daemon_pid, NULL, 0); @@ -910,8 +916,6 @@ static int __cmd_dev_del(struct dev_ctx *ctx) __func__, dev->dev_info.ublksrv_pid, number, ret); ublk_ctrl_del_dev(dev); fail: - if (ret >= 0) - ret = ublk_ctrl_get_info(dev); ublk_ctrl_deinit(dev); return (ret >= 0) ? 0 : ret; From patchwork Mon Mar 3 12:43:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 869985 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0FB520370D for ; Mon, 3 Mar 2025 12:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005840; cv=none; b=KWzcXDunjJixaYU9AuojgD5yUp6I788/EXnTYtldgyMKyFXFAMxVlO3ZuO1HbLUENIRVdxTblWB2Uh/yaH/Lx0YzAy59b2X6ceQABIhyaMp/cJiG/NSk4xtwq3AjQyTgeAm95p4BM640Lgoofgrf/o8aMelaFssqfsbzA2stIEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005840; c=relaxed/simple; bh=PALAmA07A0ocsHQIxyxYGhUW2CaWEXY/6wTWSrf84Uo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pFXfqxVSLxf7z6fM5mfw5gkzw8Q8gEgjJlCbKzkSD7s51rSg0OZG/LWZFiXBXvNdhxM2PS8Qb7iutOjBrMjgPLSDfQRfLKTi7yuUUCG0G20T5M/dQxuciUQ5b0ilCgu6Z4w/zxgaeY1OUFm2T9nveciny1kPTyKCw1swi4hyG4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iW2ssADQ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iW2ssADQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741005837; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZgHwoN4FkuivIO+yjtqGfA61kFi7hVKtRpikbqGM3uU=; b=iW2ssADQnqt5pbI3ynROtyH/T8HC3L5UaztWU6/xqbp+VznM6JCaqbizSZ3q5iVzl52VX0 WxhpojinQP3oTadeRSsj7SCqffIYr4C9PmtJOloLaP7bjQTQVvSt4gY3sJHEMs3Jrd9V8X NfCp7ZueT6c1IyzeohwrQInWwyWKhyo= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-tLrZL-b_N5ScaYPRjuEREA-1; Mon, 03 Mar 2025 07:43:54 -0500 X-MC-Unique: tLrZL-b_N5ScaYPRjuEREA-1 X-Mimecast-MFC-AGG-ID: tLrZL-b_N5ScaYPRjuEREA_1741005833 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5142D1944D03; Mon, 3 Mar 2025 12:43:53 +0000 (UTC) Received: from localhost (unknown [10.72.120.23]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F3CA0180087D; Mon, 3 Mar 2025 12:43:51 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Ming Lei Subject: [PATCH 03/11] selftests: ublk: add --foreground command line Date: Mon, 3 Mar 2025 20:43:13 +0800 Message-ID: <20250303124324.3563605-4-ming.lei@redhat.com> In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com> References: <20250303124324.3563605-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Add --foreground command for helping to debug. Signed-off-by: Ming Lei --- tools/testing/selftests/ublk/kublk.c | 17 +++++++++++++---- tools/testing/selftests/ublk/kublk.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c index 2072d880fdc4..24557a3e5508 100644 --- a/tools/testing/selftests/ublk/kublk.c +++ b/tools/testing/selftests/ublk/kublk.c @@ -679,7 +679,10 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev) } ublk_ctrl_get_info(dev); - ublk_send_dev_event(ctx, dev->dev_info.dev_id); + if (ctx->fg) + ublk_ctrl_dump(dev); + else + ublk_send_dev_event(ctx, dev->dev_info.dev_id); /* wait until we are terminated */ for (i = 0; i < dinfo->nr_hw_queues; i++) @@ -867,6 +870,9 @@ static int cmd_dev_add(struct dev_ctx *ctx) { int res; + if (ctx->fg) + goto run; + ctx->_evtfd = eventfd(0, 0); if (ctx->_evtfd < 0) { ublk_err("%s: failed to create eventfd %s\n", __func__, strerror(errno)); @@ -876,8 +882,9 @@ static int cmd_dev_add(struct dev_ctx *ctx) setsid(); res = fork(); if (res == 0) { - __cmd_dev_add(ctx); - exit(EXIT_SUCCESS); +run: + res = __cmd_dev_add(ctx); + return res; } else if (res > 0) { uint64_t id; @@ -1044,6 +1051,7 @@ int main(int argc, char *argv[]) { "debug_mask", 1, NULL, 0 }, { "quiet", 0, NULL, 0 }, { "zero_copy", 1, NULL, 'z' }, + { "foreground", 0, NULL, 0 }, { 0, 0, 0, 0 } }; int option_idx, opt; @@ -1087,7 +1095,8 @@ int main(int argc, char *argv[]) ublk_dbg_mask = strtol(optarg, NULL, 16); if (!strcmp(longopts[option_idx].name, "quiet")) ublk_dbg_mask = 0; - break; + if (!strcmp(longopts[option_idx].name, "foreground")) + ctx.fg = 1; } } diff --git a/tools/testing/selftests/ublk/kublk.h b/tools/testing/selftests/ublk/kublk.h index 8f48eb8568ab..26d9aa9c5ca2 100644 --- a/tools/testing/selftests/ublk/kublk.h +++ b/tools/testing/selftests/ublk/kublk.h @@ -67,6 +67,7 @@ struct dev_ctx { char *files[MAX_BACK_FILES]; unsigned int logging:1; unsigned int all:1; + unsigned int fg:1; int _evtfd; }; From patchwork Mon Mar 3 12:43:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 869984 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DD5D21127E for ; Mon, 3 Mar 2025 12:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005847; cv=none; b=da77qbja6erCqK/YjXPa12wN+Y7q12k6TfQcWPhCGfpIIIKv6LT2y4xBLdimQOFRDgEMP4GI40ME5dNRrKZJ7kc0O/rW07D9hkZB8QAGQ2LP2dQ0oQJpMGiMMq1es5QRL2lICmA0/qS2ltx5VqZEHT+YqEEFypXfYTeA/9XPkD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005847; c=relaxed/simple; bh=+L7g5LVGLGO8UFwoz4/X5nTzXoTux7jDxGJmh4Nm13c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PNcCilLZxQ+vaFXle9gXpcybXfeig20BMtINiW80LmhdSX/sjil+vQ/WsghjHbtAIcYdmOKEFOklL8FgFbUBPJpx7lE354Gd6reDmp1s7raRxRs0wGWqwFy8DUuNylaC4PEXpqixmSV5kPAXlxB0rB95Y9nu6UbKEdXm5hy/pCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=h/zFxdsk; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h/zFxdsk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741005845; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OnHBK1HYK0ZFpwRyuFhNqPfICJsUezdxJ+0g7/+cX+w=; b=h/zFxdsk36LcoyRVa1y0ndzl9ED+iHdU3WZv7DnvdM2TojLIYN0mGsXNrFVmc0tjb6NulD sYfcjDoC1rFnrdevZrzL5ndgZeDInsuxp/c1DxxqEGRj4TTqpym5M2xjC0WWUAGviha9ou jnP8Ijc/ILmx7x8g4hLizmgHlMpQVF4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-153-GYSUIPjRNS2QIqcklsuBuw-1; Mon, 03 Mar 2025 07:44:03 -0500 X-MC-Unique: GYSUIPjRNS2QIqcklsuBuw-1 X-Mimecast-MFC-AGG-ID: GYSUIPjRNS2QIqcklsuBuw_1741005842 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B59081954204; Mon, 3 Mar 2025 12:44:02 +0000 (UTC) Received: from localhost (unknown [10.72.120.23]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BAD9D180087D; Mon, 3 Mar 2025 12:44:00 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Ming Lei Subject: [PATCH 05/11] selftests: ublk: support shellcheck and fix all warning Date: Mon, 3 Mar 2025 20:43:15 +0800 Message-ID: <20250303124324.3563605-6-ming.lei@redhat.com> In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com> References: <20250303124324.3563605-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Add shellcheck, meantime fixes all warnings. Signed-off-by: Ming Lei --- tools/testing/selftests/ublk/Makefile | 3 ++ tools/testing/selftests/ublk/test_common.sh | 57 +++++++++++--------- tools/testing/selftests/ublk/test_loop_01.sh | 10 ++-- tools/testing/selftests/ublk/test_loop_02.sh | 10 ++-- tools/testing/selftests/ublk/test_loop_03.sh | 10 ++-- tools/testing/selftests/ublk/test_loop_04.sh | 10 ++-- tools/testing/selftests/ublk/test_null_01.sh | 6 +-- 7 files changed, 58 insertions(+), 48 deletions(-) diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile index 555a3ba5b481..9415f6f6df48 100644 --- a/tools/testing/selftests/ublk/Makefile +++ b/tools/testing/selftests/ublk/Makefile @@ -14,3 +14,6 @@ TEST_GEN_PROGS_EXTENDED = kublk include ../lib.mk $(TEST_GEN_PROGS_EXTENDED): kublk.c null.c file_backed.c + +check: + shellcheck -x -f gcc *.sh diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh index 304f22ffda58..61044cb58138 100755 --- a/tools/testing/selftests/ublk/test_common.sh +++ b/tools/testing/selftests/ublk/test_common.sh @@ -3,46 +3,49 @@ _create_backfile() { local my_size=$1 - local my_file=`mktemp ublk_bpf_${my_size}_XXXXX` + local my_file - truncate -s ${my_size} ${my_file} - echo $my_file + my_file=$(mktemp ublk_file_"${my_size}"_XXXXX) + truncate -s "${my_size}" "${my_file}" + echo "$my_file" } _remove_backfile() { local file=$1 - [ -f "$file" ] && rm -f $file + [ -f "$file" ] && rm -f "$file" } _create_tmp_dir() { - local my_file=`mktemp -d ublk_bpf_dir_XXXXX` + local my_file; - echo $my_file + my_file=$(mktemp -d ublk_dir_XXXXX) + echo "$my_file" } _remove_tmp_dir() { local dir=$1 - [ -d "$dir" ] && rmdir $dir + [ -d "$dir" ] && rmdir "$dir" } _mkfs_mount_test() { local dev=$1 local err_code=0 - local mnt_dir=`_create_tmp_dir` + local mnt_dir; - mkfs.ext4 -F $dev > /dev/null 2>&1 + mnt_dir=$(_create_tmp_dir) + mkfs.ext4 -F "$dev" > /dev/null 2>&1 err_code=$? if [ $err_code -ne 0 ]; then return $err_code fi - mount -t ext4 $dev $mnt_dir > /dev/null 2>&1 - umount $dev + mount -t ext4 "$dev" "$mnt_dir" > /dev/null 2>&1 + umount "$dev" err_code=$? - _remove_tmp_dir $mnt_dir + _remove_tmp_dir "$mnt_dir" if [ $err_code -ne 0 ]; then return $err_code fi @@ -73,12 +76,12 @@ _prep_test() { _check_root local type=$1 shift 1 - echo "ublk $type: $@" + echo "ublk $type: $*" } _show_result() { - if [ $2 -ne 0 ]; then + if [ "$2" -ne 0 ]; then echo "$1 : [FAIL]" else echo "$1 : [PASS]" @@ -86,28 +89,32 @@ _show_result() } _cleanup_test() { - ${UBLK_PROG} del -n $1 + "${UBLK_PROG}" del -n "$1" } _add_ublk_dev() { - local kublk_temp=`mktemp /tmp/kublk-XXXXXX` - ${UBLK_PROG} add $@ > ${kublk_temp} 2>&1 - if [ $? -ne 0 ]; then - echo "fail to add ublk dev $@" - exit -1 + local kublk_temp; + local dev_id; + + kublk_temp=$(mktemp /tmp/kublk-XXXXXX) + if ! "${UBLK_PROG}" add "$@" > "${kublk_temp}" 2>&1; then + echo "fail to add ublk dev $*" + return 255 fi - local dev_id=`grep "dev id" ${kublk_temp} | awk -F '[ :]' '{print $3}'` + + dev_id=$(grep "dev id" "${kublk_temp}" | awk -F '[ :]' '{print $3}') udevadm settle - rm -f ${kublk_temp} - echo ${dev_id} + rm -f "${kublk_temp}" + echo "${dev_id}" } _have_feature() { - if $UBLK_PROG "features" | grep $1 > /dev/null 2>&1; then + if "$UBLK_PROG" "features" | grep "$1" > /dev/null 2>&1; then return 0 fi return 1 } -export UBLK_PROG=$(pwd)/kublk +UBLK_PROG=$(pwd)/kublk +export UBLK_PROG diff --git a/tools/testing/selftests/ublk/test_loop_01.sh b/tools/testing/selftests/ublk/test_loop_01.sh index 829e8df05942..1d3f934dca4c 100755 --- a/tools/testing/selftests/ublk/test_loop_01.sh +++ b/tools/testing/selftests/ublk/test_loop_01.sh @@ -8,13 +8,13 @@ ERR_CODE=0 _prep_test "loop" "write and verify test" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop $backfile_0` +dev_id=$(_add_ublk_dev -t loop "$backfile_0") # run fio over the ublk disk fio --name=write_and_verify \ - --filename=/dev/ublkb${dev_id} \ + --filename=/dev/ublkb"${dev_id}" \ --ioengine=libaio --iodepth=16 \ --rw=write \ --size=256M \ @@ -24,8 +24,8 @@ fio --name=write_and_verify \ --bs=4k > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE diff --git a/tools/testing/selftests/ublk/test_loop_02.sh b/tools/testing/selftests/ublk/test_loop_02.sh index c71ae63059b8..df06b7804881 100755 --- a/tools/testing/selftests/ublk/test_loop_02.sh +++ b/tools/testing/selftests/ublk/test_loop_02.sh @@ -8,15 +8,15 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop $backfile_0` +dev_id=$(_add_ublk_dev -t loop "$backfile_0") -_mkfs_mount_test /dev/ublkb${dev_id} +_mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE diff --git a/tools/testing/selftests/ublk/test_loop_03.sh b/tools/testing/selftests/ublk/test_loop_03.sh index e781ac6db6b4..2255b4296590 100755 --- a/tools/testing/selftests/ublk/test_loop_03.sh +++ b/tools/testing/selftests/ublk/test_loop_03.sh @@ -10,13 +10,13 @@ _have_feature "ZERO_COPY" || exit 4 _prep_test "loop" "write and verify over zero copy" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop $backfile_0 -z` +dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") # run fio over the ublk disk fio --name=write_and_verify \ - --filename=/dev/ublkb${dev_id} \ + --filename=/dev/ublkb"${dev_id}" \ --ioengine=libaio --iodepth=64 \ --rw=write \ --size=256M \ @@ -26,8 +26,8 @@ fio --name=write_and_verify \ --bs=4k > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE diff --git a/tools/testing/selftests/ublk/test_loop_04.sh b/tools/testing/selftests/ublk/test_loop_04.sh index 6ab67247c809..a797b25213ec 100755 --- a/tools/testing/selftests/ublk/test_loop_04.sh +++ b/tools/testing/selftests/ublk/test_loop_04.sh @@ -8,15 +8,15 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount with zero copy" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop -z $backfile_0` +dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") -_mkfs_mount_test /dev/ublkb${dev_id} +_mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE diff --git a/tools/testing/selftests/ublk/test_null_01.sh b/tools/testing/selftests/ublk/test_null_01.sh index 04fc3ac7c716..b048ddc4ae6f 100755 --- a/tools/testing/selftests/ublk/test_null_01.sh +++ b/tools/testing/selftests/ublk/test_null_01.sh @@ -8,12 +8,12 @@ ERR_CODE=0 _prep_test "null" "basic IO test" -dev_id=`_add_ublk_dev -t null` +dev_id=$(_add_ublk_dev -t null) # run fio over the two disks -fio --name=job1 --filename=/dev/ublkb${dev_id} --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1 +fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test ${dev_id} "null" +_cleanup_test "${dev_id}" "null" _show_result $TID $ERR_CODE From patchwork Mon Mar 3 12:43:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 869982 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D7CD210F71 for ; Mon, 3 Mar 2025 12:44:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005868; cv=none; b=caIQrAVcbwk6joQX5J+L2JGs3176pgAxjObYl8bzatqDxGLeXcvY5OfeSFx13W9Gb0xKkom2HVT4vYA9DxQqDDTe+BvbeVs1KJT0Y+BqiTzFUzoYWmAXfFaXsUKfMIAzEtv9QpknYdkZn4eUbMJaxQKpz1oL0khksiIwYWhY72k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005868; c=relaxed/simple; bh=0C4JkgXQtgeQhzwqubMe5Df6hevktRFvQ5zMLbbFak4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mG7C08zhpd/u5oZIFn3cEN7oD5fJWsMVDueP6aZerhpxg9K4aMSQ2FK6p3rs5Ecc/0/fG5zPPKv+ORVvgxYwSxRb2zKwVXoqe1U0NneDAql94kjs051sCUyk+pkpFDYv6MmdIQy8reKlTPdva5K+NntYbCCWM1P5sN8IHdquhFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=YoxMQhRI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YoxMQhRI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741005866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9d+oOheGf64mOyEFfcHgMgXsNl0DuQhJwDS4FGt+uBk=; b=YoxMQhRIKqXd97r1b15/O7Oxm6eLMzDvzdS8DKA0h499ImLBLk1WS3NWfxX2f2xmy4h1gL ddRGSwK4Wnaqk+Jv01GJ6QFGKpCZw2nFuT0SGlx0guqpAobgZPz5myG9b1l8s6nBoK3SlR mQnyB1iv9lRQq6bGdJL4lWUvtlcI0DY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-157-fL6fEFKPMf6neXXldNwNMw-1; Mon, 03 Mar 2025 07:44:13 -0500 X-MC-Unique: fL6fEFKPMf6neXXldNwNMw-1 X-Mimecast-MFC-AGG-ID: fL6fEFKPMf6neXXldNwNMw_1741005852 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2EBD71800877; Mon, 3 Mar 2025 12:44:12 +0000 (UTC) Received: from localhost (unknown [10.72.120.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 112691800359; Mon, 3 Mar 2025 12:44:10 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Ming Lei Subject: [PATCH 07/11] selftests: ublk: move zero copy feature check into _add_ublk_dev() Date: Mon, 3 Mar 2025 20:43:17 +0800 Message-ID: <20250303124324.3563605-8-ming.lei@redhat.com> In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com> References: <20250303124324.3563605-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Move zero copy feature check into _add_ublk_dev() since we will have more tests which requires to cover zero copy. Then one check function of _check_add_dev() has to be added for dealing with cleanup since '_add_ublk_dev()' is run in sub-shell, and we can't exit from it to terminal shell. Meantime always return error code from _add_ublk_dev(). Signed-off-by: Ming Lei --- tools/testing/selftests/ublk/test_common.sh | 56 ++++++++++++++++---- tools/testing/selftests/ublk/test_loop_01.sh | 1 + tools/testing/selftests/ublk/test_loop_02.sh | 2 +- tools/testing/selftests/ublk/test_loop_03.sh | 4 +- tools/testing/selftests/ublk/test_loop_04.sh | 2 +- tools/testing/selftests/ublk/test_null_01.sh | 1 + 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh index d70690281d14..40bf42f1bed2 100755 --- a/tools/testing/selftests/ublk/test_common.sh +++ b/tools/testing/selftests/ublk/test_common.sh @@ -1,6 +1,8 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +UBLK_SKIP_CODE=4 + _create_backfile() { local my_size=$1 local my_file @@ -79,12 +81,37 @@ _prep_test() { echo "ublk $type: $*" } +_remove_test_files() +{ + local files=$* + + for file in ${files}; do + [ -f "${file}" ] && rm -f "${file}" + done +} + _show_result() { - if [ "$2" -ne 0 ]; then - echo "$1 : [FAIL]" - else + if [ "$2" -eq 0 ]; then echo "$1 : [PASS]" + elif [ "$2" -eq 4 ]; then + echo "$1 : [SKIP]" + else + echo "$1 : [FAIL]" + fi + [ "$2" -ne 0 ] && exit "$2" + return 0 +} + +# don't call from sub-shell, otherwise can't exit +_check_add_dev() +{ + local tid=$1 + local code=$2 + shift 2 + if [ "${code}" -ne 0 ]; then + _remove_test_files "$@" + _show_result "${tid}" "${code}" fi } @@ -92,13 +119,28 @@ _cleanup_test() { "${UBLK_PROG}" del -a } +_have_feature() +{ + if $UBLK_PROG "features" | grep "$1" > /dev/null 2>&1; then + return 0 + fi + return 1 +} + _add_ublk_dev() { local kublk_temp; local dev_id; + if echo "$@" | grep -q "\-z"; then + if ! _have_feature "ZERO_COPY"; then + return ${UBLK_SKIP_CODE} + fi + fi + kublk_temp=$(mktemp /tmp/kublk-XXXXXX) if ! "${UBLK_PROG}" add "$@" > "${kublk_temp}" 2>&1; then echo "fail to add ublk dev $*" + rm -f "${kublk_temp}" return 255 fi @@ -108,13 +150,5 @@ _add_ublk_dev() { echo "${dev_id}" } -_have_feature() -{ - if "$UBLK_PROG" "features" | grep "$1" > /dev/null 2>&1; then - return 0 - fi - return 1 -} - UBLK_PROG=$(pwd)/kublk export UBLK_PROG diff --git a/tools/testing/selftests/ublk/test_loop_01.sh b/tools/testing/selftests/ublk/test_loop_01.sh index 48a85796ca43..12bba9e5daa5 100755 --- a/tools/testing/selftests/ublk/test_loop_01.sh +++ b/tools/testing/selftests/ublk/test_loop_01.sh @@ -11,6 +11,7 @@ _prep_test "loop" "write and verify test" backfile_0=$(_create_backfile 256M) dev_id=$(_add_ublk_dev -t loop "$backfile_0") +_check_add_dev $TID $? "${backfile_0}" # run fio over the ublk disk fio --name=write_and_verify \ diff --git a/tools/testing/selftests/ublk/test_loop_02.sh b/tools/testing/selftests/ublk/test_loop_02.sh index 0a4b5fadbc73..9a163296ac83 100755 --- a/tools/testing/selftests/ublk/test_loop_02.sh +++ b/tools/testing/selftests/ublk/test_loop_02.sh @@ -9,8 +9,8 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount" backfile_0=$(_create_backfile 256M) - dev_id=$(_add_ublk_dev -t loop "$backfile_0") +_check_add_dev $TID $? "$backfile_0" _mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? diff --git a/tools/testing/selftests/ublk/test_loop_03.sh b/tools/testing/selftests/ublk/test_loop_03.sh index 5a11356e502c..72a1d072cfbd 100755 --- a/tools/testing/selftests/ublk/test_loop_03.sh +++ b/tools/testing/selftests/ublk/test_loop_03.sh @@ -6,13 +6,11 @@ TID="loop_03" ERR_CODE=0 -_have_feature "ZERO_COPY" || exit 4 - _prep_test "loop" "write and verify over zero copy" backfile_0=$(_create_backfile 256M) - dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") +_check_add_dev $TID $? "$backfile_0" # run fio over the ublk disk fio --name=write_and_verify \ diff --git a/tools/testing/selftests/ublk/test_loop_04.sh b/tools/testing/selftests/ublk/test_loop_04.sh index 7e0d4dd8127e..676c4652d758 100755 --- a/tools/testing/selftests/ublk/test_loop_04.sh +++ b/tools/testing/selftests/ublk/test_loop_04.sh @@ -9,8 +9,8 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount with zero copy" backfile_0=$(_create_backfile 256M) - dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") +_check_add_dev $TID $? "$backfile_0" _mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? diff --git a/tools/testing/selftests/ublk/test_null_01.sh b/tools/testing/selftests/ublk/test_null_01.sh index af11e73b7df6..e2847a50823a 100755 --- a/tools/testing/selftests/ublk/test_null_01.sh +++ b/tools/testing/selftests/ublk/test_null_01.sh @@ -9,6 +9,7 @@ ERR_CODE=0 _prep_test "null" "basic IO test" dev_id=$(_add_ublk_dev -t null) +_check_add_dev $TID $? # run fio over the two disks fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1 From patchwork Mon Mar 3 12:43:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 869983 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE09A2144D1 for ; Mon, 3 Mar 2025 12:44:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005866; cv=none; b=LO+OGLxuoeJn0G2h70VSOgs4ti89yKKdL39jiX7KJnHXkGx5PGDfriltqGDrgkFA9RqURJYD/t5Juwub/vuJ5LpXUczJMClnOZKDUuKdnuSLtggM2TNx9Ql8YJJnMN8GuWg9CME9aaePDyq9hAM9tguKwJ52lgzvXoJMLZu1Jfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005866; c=relaxed/simple; bh=yzen7vGiasuqWpPiMRv8npN+/wnYlavCS0OTkAhg93I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UDqmcJKtSvpnm1Fy2kB/mHE3fKivNHhu3Eq9xKFu/ulBi3MvijUR9rZ1VQFYwbgVXl5NMMkzSgjaGCTflSw7CIOZempCdpWpEZy5gH5QYG+lXp0aOVe95c0BmIZKoxb3Um1Rzep/Mrz9XA9yciUNqjmZE9VP02oa9d6fROai/uc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UiqZSS8v; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UiqZSS8v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741005863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=au45iy9Z4vYO/0vG2IShtPayiK/hMU7zUbUz9ZFnV1M=; b=UiqZSS8v52HJIlvyXqgxJlULSadozKLaVcKf+0MVklKw7AfkaITzNGZ6uno3BrBIJKyCtO DQVsApDPQaNkziuz6959AAG3H/lZH4R9T4Lm9zKSUm7Oy+fUTpHrbfIBDn3S6ecJBEQCo9 ZmiAzdFKbMfScgQ/WkHnCXQRbk3ysVU= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-0DHCWXsXMuiNdRb2OUunMg-1; Mon, 03 Mar 2025 07:44:22 -0500 X-MC-Unique: 0DHCWXsXMuiNdRb2OUunMg-1 X-Mimecast-MFC-AGG-ID: 0DHCWXsXMuiNdRb2OUunMg_1741005861 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1DB21801A18; Mon, 3 Mar 2025 12:44:21 +0000 (UTC) Received: from localhost (unknown [10.72.120.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5C259300019F; Mon, 3 Mar 2025 12:44:19 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Ming Lei Subject: [PATCH 09/11] selftests: ublk: add one stress test for covering IO vs. removing device Date: Mon, 3 Mar 2025 20:43:19 +0800 Message-ID: <20250303124324.3563605-10-ming.lei@redhat.com> In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com> References: <20250303124324.3563605-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Add stress_test_01 for running IO vs. removing device for verifying that ublk device removal can work as expected when heavy IO workloads are in progress. null, loop and loop/zc are covered in this tests. Signed-off-by: Ming Lei --- tools/testing/selftests/ublk/Makefile | 2 + tools/testing/selftests/ublk/test_common.sh | 26 ++++++++++ .../testing/selftests/ublk/test_stress_01.sh | 47 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100755 tools/testing/selftests/ublk/test_stress_01.sh diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile index 9415f6f6df48..40af938cd277 100644 --- a/tools/testing/selftests/ublk/Makefile +++ b/tools/testing/selftests/ublk/Makefile @@ -9,6 +9,8 @@ TEST_PROGS += test_loop_02.sh TEST_PROGS += test_loop_03.sh TEST_PROGS += test_loop_04.sh +TEST_PROGS += test_stress_01.sh + TEST_GEN_PROGS_EXTENDED = kublk include ../lib.mk diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh index bcb0c7aa3956..89244a7e275c 100755 --- a/tools/testing/selftests/ublk/test_common.sh +++ b/tools/testing/selftests/ublk/test_common.sh @@ -155,5 +155,31 @@ _add_ublk_dev() { echo "${dev_id}" } +__remove_ublk_dev_return() { + local dev_id=$1 + + ${UBLK_PROG} del -n "${dev_id}" + local res=$? + udevadm settle + return ${res} +} + +__run_io_and_remove() +{ + local dev_id=$1 + local size=$2 + + fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \ + --rw=readwrite --iodepth=64 --size="${size}" --numjobs=4 \ + --runtime=20 --time_based > /dev/null 2>&1 & + sleep 2 + if ! __remove_ublk_dev_return "${dev_id}"; then + echo "delete dev ${dev_id} failed" + return 255 + fi + wait +} + + UBLK_PROG=$(pwd)/kublk export UBLK_PROG diff --git a/tools/testing/selftests/ublk/test_stress_01.sh b/tools/testing/selftests/ublk/test_stress_01.sh new file mode 100755 index 000000000000..2dfd01cfd265 --- /dev/null +++ b/tools/testing/selftests/ublk/test_stress_01.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. test_common.sh +TID="stress_01" +ERR_CODE=0 +DEV_ID=-1 + +ublk_io_and_remove() +{ + local size=$1 + shift 1 + local backfile="" + if echo "$@" | grep -q "loop"; then + backfile=${*: -1} + fi + DEV_ID=$(_add_ublk_dev "$@") + _check_add_dev $TID $? "${backfile}" + + echo "run ublk IO vs. remove device(ublk add $*)" + if ! __run_io_and_remove "${DEV_ID}" "${size}"; then + echo "/dev/ublkc${DEV_ID} isn't removed" + _remove_backfile "${backfile}" + exit 255 + fi +} + +_prep_test "stress" "run IO and remove device" + +ublk_io_and_remove 8G -t null +ERR_CODE=$? +if [ ${ERR_CODE} -ne 0 ]; then + _show_result $TID $ERR_CODE +fi + +BACK_FILE=$(_create_backfile 256M) +ublk_io_and_remove 256M -t loop "${BACK_FILE}" +ERR_CODE=$? +if [ ${ERR_CODE} -ne 0 ]; then + _show_result $TID $ERR_CODE +fi + +ublk_io_and_remove 256M -t loop -z "${BACK_FILE}" +ERR_CODE=$? +_cleanup_test "stress" +_remove_backfile "${BACK_FILE}" +_show_result $TID $ERR_CODE From patchwork Mon Mar 3 12:43:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 869981 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 861FF210F71 for ; Mon, 3 Mar 2025 12:44:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005889; cv=none; b=XsLhWWufjKyOtYJ5vmt/nC2XOcxHLZhyQmAF1sumpeXgCgF8HpSX+b6BlyWax9XYrVk2hs3BLZrKZSOYq/jf9myZQrsuvlOwohmMHkSbf99vrDx5JU+OZZmwe83fzlfIdWBDrneopHV0SWjLNMep9KcX+lCzpWMUsCO/w5OrRh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741005889; c=relaxed/simple; bh=FGAah+nZFfve3WCpEi0Ybu1HjWrSfpCAz+yiiAE7w9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UAmJM8gifNzPhFu82ZpW5/ASUlZn8nR76z0YPfTmC8BogGlQ1YYC3831nm5RZVsWjchV4TJIbIqj+2X5tGoWWdj1rKqh/LujITlG6wYzqzU9G7S6n/m6a4yapzDZweHU+YEXo9cc5LHMukcgswbIUWKzxIB52PnSxXgJX2qn8pg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EI0HdMya; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EI0HdMya" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741005886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Quo9GFqH1Xb63xK1C4YcntZoNhBsXEt5C3tvQgLnKJE=; b=EI0HdMya3S81BCLSlia7bnaOtmVpOZgmH3R3QMub8ZegEG/dSV3LQp4972hh3koCSPoo2O 1kpgGtEbZn8PuhJu/qm5XHCvuM8cvM7OPQvO7DGQIKRQljPlPdpkH+odmaO932y42qS5kg HE+7JYYTL/kPJR66kCaDL/O1NOi/Nr0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-YU6gR_67OaKZj4tz8IcTrg-1; Mon, 03 Mar 2025 07:44:33 -0500 X-MC-Unique: YU6gR_67OaKZj4tz8IcTrg-1 X-Mimecast-MFC-AGG-ID: YU6gR_67OaKZj4tz8IcTrg_1741005872 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7E2CD19540EE; Mon, 3 Mar 2025 12:44:32 +0000 (UTC) Received: from localhost (unknown [10.72.120.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67B66300019F; Mon, 3 Mar 2025 12:44:30 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Ming Lei Subject: [PATCH 11/11] selftests: ublk: improve test usability Date: Mon, 3 Mar 2025 20:43:21 +0800 Message-ID: <20250303124324.3563605-12-ming.lei@redhat.com> In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com> References: <20250303124324.3563605-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Add UBLK_TEST_QUIET, so we can print test result(PASS/SKIP/FAIL) only. Also always run from test script's current directory, then the same test script can be started from other work directory. This way helps a lot to reuse this test source code and scripts for other projects(liburing, blktests, ...) Signed-off-by: Ming Lei --- tools/testing/selftests/ublk/test_common.sh | 10 ++++++++-- tools/testing/selftests/ublk/test_loop_01.sh | 2 +- tools/testing/selftests/ublk/test_loop_02.sh | 2 +- tools/testing/selftests/ublk/test_loop_03.sh | 2 +- tools/testing/selftests/ublk/test_loop_04.sh | 2 +- tools/testing/selftests/ublk/test_null_01.sh | 2 +- tools/testing/selftests/ublk/test_stress_01.sh | 4 ++-- tools/testing/selftests/ublk/test_stress_02.sh | 4 ++-- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh index 92596d0d0013..350380facd9f 100755 --- a/tools/testing/selftests/ublk/test_common.sh +++ b/tools/testing/selftests/ublk/test_common.sh @@ -80,7 +80,7 @@ _prep_test() { local type=$1 shift 1 modprobe ublk_drv - echo "ublk $type: $*" + [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "ublk $type: $*" } _remove_test_files() @@ -209,6 +209,12 @@ __run_io_and_remove() wait } +_ublk_test_top_dir() +{ + cd "$(dirname "$0")" && pwd +} -UBLK_PROG=$(pwd)/kublk +UBLK_PROG=$(_ublk_test_top_dir)/kublk +UBLK_TEST_QUIET=1 export UBLK_PROG +export UBLK_TEST_QUIET diff --git a/tools/testing/selftests/ublk/test_loop_01.sh b/tools/testing/selftests/ublk/test_loop_01.sh index 12bba9e5daa5..c882d2a08e13 100755 --- a/tools/testing/selftests/ublk/test_loop_01.sh +++ b/tools/testing/selftests/ublk/test_loop_01.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_01" ERR_CODE=0 diff --git a/tools/testing/selftests/ublk/test_loop_02.sh b/tools/testing/selftests/ublk/test_loop_02.sh index 9a163296ac83..03863d825e07 100755 --- a/tools/testing/selftests/ublk/test_loop_02.sh +++ b/tools/testing/selftests/ublk/test_loop_02.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_02" ERR_CODE=0 diff --git a/tools/testing/selftests/ublk/test_loop_03.sh b/tools/testing/selftests/ublk/test_loop_03.sh index 72a1d072cfbd..269c96787d7d 100755 --- a/tools/testing/selftests/ublk/test_loop_03.sh +++ b/tools/testing/selftests/ublk/test_loop_03.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_03" ERR_CODE=0 diff --git a/tools/testing/selftests/ublk/test_loop_04.sh b/tools/testing/selftests/ublk/test_loop_04.sh index 676c4652d758..1435422c38ec 100755 --- a/tools/testing/selftests/ublk/test_loop_04.sh +++ b/tools/testing/selftests/ublk/test_loop_04.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_04" ERR_CODE=0 diff --git a/tools/testing/selftests/ublk/test_null_01.sh b/tools/testing/selftests/ublk/test_null_01.sh index e2847a50823a..a34203f72668 100755 --- a/tools/testing/selftests/ublk/test_null_01.sh +++ b/tools/testing/selftests/ublk/test_null_01.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="null_01" ERR_CODE=0 diff --git a/tools/testing/selftests/ublk/test_stress_01.sh b/tools/testing/selftests/ublk/test_stress_01.sh index c1cdde3e79f7..7177f6c57bc5 100755 --- a/tools/testing/selftests/ublk/test_stress_01.sh +++ b/tools/testing/selftests/ublk/test_stress_01.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="stress_01" ERR_CODE=0 DEV_ID=-1 @@ -17,7 +17,7 @@ ublk_io_and_remove() DEV_ID=$(_add_ublk_dev "$@") _check_add_dev $TID $? "${backfile}" - echo "run ublk IO vs. remove device(ublk add $*)" + [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "run ublk IO vs. remove device(ublk add $*)" if ! __run_io_and_remove "${DEV_ID}" "${size}" "no"; then echo "/dev/ublkc${DEV_ID} isn't removed" _remove_backfile "${backfile}" diff --git a/tools/testing/selftests/ublk/test_stress_02.sh b/tools/testing/selftests/ublk/test_stress_02.sh index ec758f649a97..2a8e60579a06 100755 --- a/tools/testing/selftests/ublk/test_stress_02.sh +++ b/tools/testing/selftests/ublk/test_stress_02.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="stress_02" ERR_CODE=0 DEV_ID=-1 @@ -17,7 +17,7 @@ ublk_io_and_kill_daemon() DEV_ID=$(_add_ublk_dev "$@") _check_add_dev $TID $? "${backfile}" - echo "run ublk IO vs kill ublk server(ublk add $*)" + [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "run ublk IO vs kill ublk server(ublk add $*)" if ! __run_io_and_remove "${DEV_ID}" "${size}" "yes"; then echo "/dev/ublkc${DEV_ID} isn't removed res ${res}" _remove_backfile "${backfile}"