Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1504900pxv; Fri, 2 Jul 2021 05:34:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg7HuLyliYOLsVToQNbfVE9uyh7Mv0vJ2KaQ92mZPL3hj04ILcUy4Ubp2Nksqxnuhqx5di X-Received: by 2002:aa7:d413:: with SMTP id z19mr6520306edq.37.1625229261044; Fri, 02 Jul 2021 05:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625229261; cv=none; d=google.com; s=arc-20160816; b=bvVW+xx2IFxeNibmGMjepmyQEmuEwE/eVvXhjoC+P5rZt3bOeLWvHL5pxSXukScgTR QZmRZIblWK9Mx1EuxfYZWPykUCT8ZusqHFYbtfFdjx5p5m/KnvOShy5p+OdGFql25iPT ZYh4UIvxpduZFHxJIfqKhBV6JjG57oEvJ7oLPN2piMuuFUTy20OCpFX6vXIwstiPwJDz Ad/eXBf/k5zT9EEEVCd8ydIUHEBLDKdkPitxNw3/3CBijQ9zQp2mKSRmkv5D6EfWmrvq 8Jkpj1v1HgBL68MeRromDDEAOK0TcdKWQjemyM2RLJfnNzjwuFc5dlEy63Bt7WpsahlQ g4xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+nBHdwN9B85XGQUpBodXfAKupYicBt7URNi6XfIff70=; b=fbK2XG5chGADY9aL6p0sqOTDFqoBonhPaRHzv8E/RUlU1HC6i+DxfTXdcAKdVWSOCT rElncGz/WyTGC6kT2M8HwUBEGWXuKOAO+2ELCnZH/MG813qkg25sozNvPakwRCQ4zGGP nmT1ydtV/aRl9pYJtlXVFA11gB9jS4x1TzXd1SEq/lzkswSL3T6ToWffIy9n8i0yyFq3 FKSsmdmByjOCOmka9x86yDkY/GpGLgd/TKyosAAB5K4D9muGjo3klS7L5yJKersE0JeV s9iP8/hZwDCgHvW7d7lcZsn3gGg0BMPTDnrJoQ8i7n7TSTREWXRpx/n/smmHiojKy+7N zkHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si2963490edb.164.2021.07.02.05.33.55; Fri, 02 Jul 2021 05:34:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232268AbhGBMfR (ORCPT + 99 others); Fri, 2 Jul 2021 08:35:17 -0400 Received: from mga01.intel.com ([192.55.52.88]:3459 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232227AbhGBMfO (ORCPT ); Fri, 2 Jul 2021 08:35:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="230397081" X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="230397081" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 05:32:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="642660144" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga006.fm.intel.com with ESMTP; 02 Jul 2021 05:32:39 -0700 From: Alexey Bayduraev To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: [PATCH v9 02/24] tools lib: Introduce fdarray clone function Date: Fri, 2 Jul 2021 15:32:10 +0300 Message-Id: X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a function to create a copy of an existing file descriptor in the fdarray structure. The function returns the position of the copied fd. Acked-by: Namhyung Kim Signed-off-by: Alexey Bayduraev --- tools/lib/api/fd/array.c | 17 +++++++++++++++++ tools/lib/api/fd/array.h | 1 + 2 files changed, 18 insertions(+) diff --git a/tools/lib/api/fd/array.c b/tools/lib/api/fd/array.c index 5e6cb9debe37..de8bcbaea3f1 100644 --- a/tools/lib/api/fd/array.c +++ b/tools/lib/api/fd/array.c @@ -88,6 +88,23 @@ int fdarray__add(struct fdarray *fda, int fd, short revents, enum fdarray_flags return pos; } +int fdarray__clone(struct fdarray *fda, int pos, struct fdarray *base) +{ + struct pollfd *entry; + int npos; + + if (pos >= base->nr) + return -EINVAL; + + entry = &base->entries[pos]; + + npos = fdarray__add(fda, entry->fd, entry->events, base->priv[pos].flags); + if (npos >= 0) + fda->priv[npos] = base->priv[pos]; + + return npos; +} + int fdarray__filter(struct fdarray *fda, short revents, void (*entry_destructor)(struct fdarray *fda, int fd, void *arg), void *arg) diff --git a/tools/lib/api/fd/array.h b/tools/lib/api/fd/array.h index 7fcf21a33c0c..4a03da7f1fc1 100644 --- a/tools/lib/api/fd/array.h +++ b/tools/lib/api/fd/array.h @@ -42,6 +42,7 @@ struct fdarray *fdarray__new(int nr_alloc, int nr_autogrow); void fdarray__delete(struct fdarray *fda); int fdarray__add(struct fdarray *fda, int fd, short revents, enum fdarray_flags flags); +int fdarray__clone(struct fdarray *fda, int pos, struct fdarray *base); int fdarray__poll(struct fdarray *fda, int timeout); int fdarray__filter(struct fdarray *fda, short revents, void (*entry_destructor)(struct fdarray *fda, int fd, void *arg), -- 2.19.0