From patchwork Mon Jul 27 16:44:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Gao X-Patchwork-Id: 1337083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=SLaN9WrH; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BFlyY4Bb8z9sPB for ; Tue, 28 Jul 2020 02:44:37 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 254683C60DD for ; Mon, 27 Jul 2020 18:44:33 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 722C43C26DE for ; Mon, 27 Jul 2020 18:44:12 +0200 (CEST) Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 8BA2B14001EA for ; Mon, 27 Jul 2020 18:44:11 +0200 (CEST) Received: by mail-pg1-x541.google.com with SMTP id j19so10015205pgm.11 for ; Mon, 27 Jul 2020 09:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dmhYUfNmsEsqaTAeaNgYOWyOx9YOs47wUY8mCGXP6Ls=; b=SLaN9WrHjeAdTw9eJa/iNcahqE/obsc7EbeyqE9apwgPqgXGar3QWyhmZrrgpxwuzE zBF15gIOCReJVNfY60lol9zfmPFf8n7mGFpryTU03SsNvLn/qGimbE0hx7eyGnqSBjop MaE8RAW+kTPfXahBeZr50YXHa4QmTbjcdi//hOWG6AVNAZawMWl8/XB8DlX48B71XQNZ 6M7FWpnJCP4YZbSmrxtNsYTPZdPUuD5TM8qGbShq84qmaFZQx8GlkdlD4A+Y+5Q++urv gQpeVG+WnKzpe9F8U+FGtRAY27h7PaRD1HHUtfGRUo5qIAwAaYM0olRFGQKOEWiEYOxZ FfxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dmhYUfNmsEsqaTAeaNgYOWyOx9YOs47wUY8mCGXP6Ls=; b=Ow54ol5K0RWYgUFEd3vLEr5mMO+28/uOLrG1h7tYaIE+TZeXvDnHo568ZCH2BkHpfx oEl7pByhAhwS3yhBp3pllOxDgNo49u6UKGdHbp6ovDiWkOpBnH2kjY2OzEkoFopyYoAs u5UCwAiqc2qksnr0iDgxTy3eomHS4mOg2MzJHMdKSA0J2PLeKgaXhtn0yJe9odJPZjdn eoXLtIE7W4n4UhDaqKctVHEcH12hGKKzt7GBT8RlNoSnErg3u8rrrQpx/aqtlViW2XKG m+qlOxTIiZFTXGbzbudvhWZGJWXHc+x41xeKIdSMz/qWBJUg5B+Knb2V5wn4Sks6wCMz Qbhg== X-Gm-Message-State: AOAM531C3BNBT+lqSMpxPovh3TrHtXShDpipr/Du7KJQw3tpcSf6thBR cljggk6X6DiwT8tnC5gIN2LFtSjR X-Google-Smtp-Source: ABdhPJxraH6F7/lDw1f2cUtLlUa9Oq3ZWMRs5xPJHRHNtdhuKotOEFA9cBjUs5O9aFrjSinLQ1psRA== X-Received: by 2002:a63:20d:: with SMTP id 13mr20717576pgc.166.1595868246635; Mon, 27 Jul 2020 09:44:06 -0700 (PDT) Received: from aidengao.c.googlers.com.com (15.4.198.104.bc.googleusercontent.com. [104.198.4.15]) by smtp.gmail.com with ESMTPSA id p127sm15131357pfb.17.2020.07.27.09.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:44:06 -0700 (PDT) From: aidengao To: ltp@lists.linux.it Date: Mon, 27 Jul 2020 16:44:01 +0000 Message-Id: <20200727164403.1177686-1-aiden.gaoyuan@gmail.com> X-Mailer: git-send-email 2.28.0.rc0.142.g3c755180ce-goog MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=1.7 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 1/3] hotplug/memory_hotplug: Handle NULL returned by strtok_r when parsing inputs 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: , Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: aidengao In the original version of memtoy, it uses strtok_r(args, " ", &nextarg) to split string. When strtok_r finds the last substring to be split, it will set nextarg to NULL rather than let it point to '\0'. In this case, if it wants to do something else to nextarg like calling strspn(nextarg, " "), it will throw an error. Add NULL check for nextarg to fix this error. Signed-off-by: Yuan Gao --- .../kernel/hotplug/memory_hotplug/commands.c | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/testcases/kernel/hotplug/memory_hotplug/commands.c b/testcases/kernel/hotplug/memory_hotplug/commands.c index e31743bd3..2e8972c1c 100644 --- a/testcases/kernel/hotplug/memory_hotplug/commands.c +++ b/testcases/kernel/hotplug/memory_hotplug/commands.c @@ -61,6 +61,11 @@ static char *whitespace = " \t"; +inline char *get_next_arg(char *args, char *nextarg) +{ + return nextarg ? nextarg + strspn(nextarg, whitespace) : args + strlen(args); +} + /* * ========================================================================= */ @@ -146,7 +151,7 @@ static int get_range(char *args, range_t * range, char **nextarg) range->offset = get_scaled_value(args, "offset"); if (range->offset == BOGUS_SIZE) return CMD_ERROR; - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); /* * ... only if offset specified @@ -160,7 +165,7 @@ static int get_range(char *args, range_t * range, char **nextarg) return CMD_ERROR; } else range->length = 0; /* map to end of file */ - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); } } @@ -669,7 +674,7 @@ static int anon_seg(char *args) range.length = get_scaled_value(args, "size"); if (range.length == BOGUS_SIZE) return CMD_ERROR; - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); if (*args != '\0') { segflag = get_shared(args); @@ -699,7 +704,7 @@ static int file_seg(char *args) if (!required_arg(args, "")) return CMD_ERROR; pathname = strtok_r(args, whitespace, &nextarg); - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); /* * offset, length are optional @@ -757,7 +762,7 @@ static int touch_seg(char *args) if (!required_arg(args, "")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); /* * offset, length are optional @@ -788,7 +793,7 @@ static int unmap_seg(char *args) if (!required_arg(args, "")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); if (!segment_unmap(segname)) return CMD_ERROR; @@ -812,7 +817,7 @@ static int map_seg(char *args) if (!required_arg(args, "")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); /* * offset, length are optional @@ -856,7 +861,7 @@ static int mbind_seg(char *args) if (!required_arg(args, "")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); /* * offset, length are optional @@ -871,7 +876,7 @@ static int mbind_seg(char *args) if (policy < 0) return CMD_ERROR; - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); if (*args == '+') { flags = get_mbind_flags(++args, &nextarg); if (flags == -1) @@ -914,7 +919,7 @@ static int shmem_seg(char *args) if (!required_arg(args, "")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); if (!required_arg(args, "")) return CMD_ERROR; @@ -922,7 +927,7 @@ static int shmem_seg(char *args) range.length = get_scaled_value(args, "size"); if (range.length == BOGUS_SIZE) return CMD_ERROR; - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); if (!segment_register(SEGT_SHM, segname, &range, MAP_SHARED)) return CMD_ERROR; @@ -954,7 +959,7 @@ static int where_seg(char *args) if (!required_arg(args, "")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); - args = nextarg + strspn(nextarg, whitespace); + args = get_next_arg(args, nextarg); /* * offset, length are optional From patchwork Mon Jul 27 16:44:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Gao X-Patchwork-Id: 1337081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=jCuAP1Et; dkim-atps=neutral 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BFly915GLz9sR4 for ; Tue, 28 Jul 2020 02:44:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5C07E3C2EFC for ; Mon, 27 Jul 2020 18:44:14 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id AC7BF3C60E6 for ; Mon, 27 Jul 2020 18:44:09 +0200 (CEST) Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id D2BE2600C98 for ; Mon, 27 Jul 2020 18:44:08 +0200 (CEST) Received: by mail-pg1-x543.google.com with SMTP id e8so10010737pgc.5 for ; Mon, 27 Jul 2020 09:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ybjMKtmvZGrPj3TXu2VriSa6zRUNpuFnnPwGzL5eVEI=; b=jCuAP1EtzSCzJSfhPrSw+umYqfDn1ehQTu6Hf9yjcVEDU5FafRoqS2Shi9Fv+M6qx+ I0A5xi+ZeAY8fuN2nXaVxssYczHjm7A2opjn8L9EuRoSKpv2iwEFBHHFe0h0ikZ0tPkz pJlBzXbV+QzgCa2e9NenQ1miFrrcXRPf1K/nJldf+1xKGJ/6bFZjEokJg3H03W4Vsv3r vB2RB9KbR2zX8L6uD5Mhq7NUBBYMl2MjfVD/CXXPzVYcqGYkY9CYqAdb/FcNOGGSMQ0t j0l+dwyLZ3uzF8vOMnQ3UxI+z2ta+5rendFJvEsXBnjTAaYhb+2BkvUrdJ89Nddpo6aQ UMqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ybjMKtmvZGrPj3TXu2VriSa6zRUNpuFnnPwGzL5eVEI=; b=so4Uxb3l8cUT+FdRiNma+oWBYTPumZFeKE7fQ5DoFB1XyLUd9slvFcpB43O07L3RD5 SrnTjXWNiNeXJ4ht0BWQ4k7/Qkh0HL4AaIK6uKmaIJR2z4cVel98notbigQxvE9u7J5Z LqCxijCQzDnRklXGBGiSqWypDwAC6/tiIJ6amNXyZpgEjgD8Nk6a21earkvYGQ+yD5Ss TtNa3pl6aIttjvVdLjr1WfRhIeCOuQ2kqsAyTD0HEndROpvpVyyPUpKlcL9cyH5z6arK +h7zWEB1VURN7sk19cFj+a2VIemdGYxgzoJYMpu1hnFo0kyqH3In7thARLooe70rqsvf zbUw== X-Gm-Message-State: AOAM533r2VIYtPs76M4AwkY3lyHW1Lt7MeMarZ8sLhJB4jAQGbbD9quD 3CGxjfmqVeKmk/nQ1MYdOgLZZrxb X-Google-Smtp-Source: ABdhPJwI+8W1AX+R8aIsw0luxvpzoPVuv7guHO/DifnseI3gLuDDUkEbiAkbxRW+x8WHDZzGKoA7aQ== X-Received: by 2002:a65:60d4:: with SMTP id r20mr20193915pgv.436.1595868247286; Mon, 27 Jul 2020 09:44:07 -0700 (PDT) Received: from aidengao.c.googlers.com.com (15.4.198.104.bc.googleusercontent.com. [104.198.4.15]) by smtp.gmail.com with ESMTPSA id p127sm15131357pfb.17.2020.07.27.09.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:44:06 -0700 (PDT) From: aidengao To: ltp@lists.linux.it Date: Mon, 27 Jul 2020 16:44:02 +0000 Message-Id: <20200727164403.1177686-2-aiden.gaoyuan@gmail.com> X-Mailer: git-send-email 2.28.0.rc0.142.g3c755180ce-goog In-Reply-To: <20200727164403.1177686-1-aiden.gaoyuan@gmail.com> References: <20200727164403.1177686-1-aiden.gaoyuan@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=1.7 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH 2/3] hotplug/memory_hotplug: Add a memtoy command to create a file of specified size 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: , Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: aidengao Add a new memtoy command for interactively creating an empty file of specified size. USAGE: createfile [k|m|p|g] Example: createfile /data/local/tmp 100m This will create a file named temp in /data/local/tmp/ with the size of 100 megabytes. Signed-off-by: Yuan Gao --- .../kernel/hotplug/memory_hotplug/commands.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/testcases/kernel/hotplug/memory_hotplug/commands.c b/testcases/kernel/hotplug/memory_hotplug/commands.c index 2e8972c1c..d37c6b40b 100644 --- a/testcases/kernel/hotplug/memory_hotplug/commands.c +++ b/testcases/kernel/hotplug/memory_hotplug/commands.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -725,6 +726,44 @@ static int file_seg(char *args) return CMD_SUCCESS; } +/* + * createfile [k|m|g|p]] + */ +static int create_file(char *args) +{ + char *filename, *nextarg; + size_t len; + int fd; + + args += strspn(args, whitespace); + if (!required_arg(args, "")) + return CMD_ERROR; + filename = strtok_r(args, whitespace, &nextarg); + args = nextarg + strspn(nextarg, whitespace); + + if (!required_arg(args, "")) + return CMD_ERROR; + args = strtok_r(args, whitespace, &nextarg); + len = get_scaled_value(args, "size"); + if (len == BOGUS_SIZE) + return CMD_ERROR; + args = get_next_arg(args, nextarg); + + fd = open(filename, O_RDWR | O_CREAT, 0600); + if (fd < 0) { + printf("Fail to create a file %s\n", filename); + return CMD_ERROR; + } + + if (posix_fallocate(fd, 0, len)) { + printf("Fail to create a file %s\n", filename); + return CMD_ERROR; + } + close(fd); + return CMD_SUCCESS; +} + + /* * remove_seg: [ ...] */ @@ -1029,6 +1068,8 @@ struct command { "\tspecified offset into the file. and may be\n" "\tomitted and specified on the map command.\n" "\t := private|shared - default = private\n"}, { + .cmd_name = "createfile", .cmd_func = create_file, .cmd_help = + "createfile [k|m|g|p]]",}, { .cmd_name = "shm",.cmd_func = shmem_seg,.cmd_help = "shm [k|m|g|p] - \n" "\tdefine a shared memory segment of specified size.\n" From patchwork Mon Jul 27 16:44:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Gao X-Patchwork-Id: 1337082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ItUIrA8z; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BFlyL4XxJz9sPB for ; Tue, 28 Jul 2020 02:44:26 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D593F3C26C0 for ; Mon, 27 Jul 2020 18:44:23 +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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 2548B3C60E6 for ; Mon, 27 Jul 2020 18:44:10 +0200 (CEST) Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 780492348D6 for ; Mon, 27 Jul 2020 18:44:09 +0200 (CEST) Received: by mail-pg1-x544.google.com with SMTP id o13so10041566pgf.0 for ; Mon, 27 Jul 2020 09:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=54LrZxiP1yUemLeoxohjPb4XMwnzS/JHohGhK84c5xA=; b=ItUIrA8zINthl7rfejI0sWgw1ITnd7ozJaQKd7exjAZmFkxqK+yiEdQdBDRTqM9h5i 3yKtYYnuxJGd1AkNrlRKTB7WuFoajEdZASE79XcTngDzFHCGPR8hY8hSgJMJHDe04LPU DK5PljxZy+tK/adQ6A5IgNxqJ7eGjUOnFVW5o9EU30O8+d7sGrqrjqEfUpp2A6rmGgfH ReIF2XHixWXmzN8bkhGA2282T8Sc+LvHUlHY3SoypMu1dqAnScjy7o2ugqWLmuBEBp4E qn8RKnaRMrAgbfCC1FN6Ywe/WyuqE5DCQr9cGMAzpCD0P7xX8XV0m8CWIytx4UnarwS4 xOkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=54LrZxiP1yUemLeoxohjPb4XMwnzS/JHohGhK84c5xA=; b=MZe55jH2FDfMMXij7GmY8R6OU/BfHvXc5Ekmg8dS9z3d5Zi5Zc0AK9LH77I4k7pgUC Lwd8rX98UIexrhbjeNw4qJlh1Kud055e4GMcvYj+C4E88PoW/OzC34UNoryrJWp2GGSb 8uo1FoxiOqF43PF3UrWz5HJGTAre1tTtZRKaME/9sTvo0E/nYuRoke77Dl1SIZp48VyD XmEHshrgWac44sE3HHh4gthIGskNx5ax8SLScbv/9nJpf+2O3bxfgYvsFXfQLehCUL3s lo3JqgiZzls3dL572ZoINNN4q48fRfQFVSWZPr4sdxuu9vCvCHCMS+uobcJE++LsCePl TXsw== X-Gm-Message-State: AOAM530vMzOZ+T8jpa+AlTSZXnkce3Mtc6Dck/+50YfdZ55nGpQ+v5nA MNqzO5jdGPbWTLeavfrzhsi2BST1 X-Google-Smtp-Source: ABdhPJzi/gj36dFoqVDBfyD7lF4xei9LU6ZoFDPHJvv2OBMe6X20N9BDsDtub6ZdLr+lHtlzoCshRQ== X-Received: by 2002:a63:560f:: with SMTP id k15mr19913896pgb.162.1595868247872; Mon, 27 Jul 2020 09:44:07 -0700 (PDT) Received: from aidengao.c.googlers.com.com (15.4.198.104.bc.googleusercontent.com. [104.198.4.15]) by smtp.gmail.com with ESMTPSA id p127sm15131357pfb.17.2020.07.27.09.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:44:07 -0700 (PDT) From: aidengao To: ltp@lists.linux.it Date: Mon, 27 Jul 2020 16:44:03 +0000 Message-Id: <20200727164403.1177686-3-aiden.gaoyuan@gmail.com> X-Mailer: git-send-email 2.28.0.rc0.142.g3c755180ce-goog In-Reply-To: <20200727164403.1177686-1-aiden.gaoyuan@gmail.com> References: <20200727164403.1177686-1-aiden.gaoyuan@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=1.7 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 3/3] hotplug/memory_hotplug: Add a memtoy command to delete a file 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: , Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: aidengao Add a new memtoy command for interactively deleting a file. USAGE: deletefile Example: deletefile /data/local/tmp This will delete a file named tmp in /data/local Signed-off-by: Yuan Gao --- .../kernel/hotplug/memory_hotplug/commands.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/testcases/kernel/hotplug/memory_hotplug/commands.c b/testcases/kernel/hotplug/memory_hotplug/commands.c index d37c6b40b..0aa32ebea 100644 --- a/testcases/kernel/hotplug/memory_hotplug/commands.c +++ b/testcases/kernel/hotplug/memory_hotplug/commands.c @@ -726,6 +726,26 @@ static int file_seg(char *args) return CMD_SUCCESS; } +/* + * deletefile + */ +static int delete_file(char *args) +{ + char *filename, *nextarg; + + args += strspn(args, whitespace); + if (!required_arg(args, "")) + return CMD_ERROR; + filename = strtok_r(args, whitespace, &nextarg); + + if (remove(filename)) { + printf("Fail to delete a file %s\n", filename); + return CMD_ERROR; + } + + return CMD_SUCCESS; +} + /* * createfile [k|m|g|p]] */ @@ -1070,6 +1090,8 @@ struct command { "\t := private|shared - default = private\n"}, { .cmd_name = "createfile", .cmd_func = create_file, .cmd_help = "createfile [k|m|g|p]]",}, { + .cmd_name = "deletefile", .cmd_func = delete_file, .cmd_help = + "deletefile "}, { .cmd_name = "shm",.cmd_func = shmem_seg,.cmd_help = "shm [k|m|g|p] - \n" "\tdefine a shared memory segment of specified size.\n"