Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1012591pxb; Tue, 17 Aug 2021 01:25:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4tAYtmYdoKUAh/jS3dMpdLqXaiEjdm/Mp3Hc741tV3MG7g02iuUjbvMB7YHVpG+9e20Si X-Received: by 2002:a05:6402:10d6:: with SMTP id p22mr2847813edu.168.1629188734755; Tue, 17 Aug 2021 01:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629188734; cv=none; d=google.com; s=arc-20160816; b=V3g/XBkasUN+Wx3vNgmfWkIfgdzkRIdbDzGPwMosZ8Ev9jdTXPUcauqV0qb5z+rTP1 cPJgR/N8kIJVb+E+6Dy2c8r2/IP+VlIZKREjh8LA2+kuy0GXEt5kLZ3xZSNlXFcFwKBl SmSy/csdSM4ZlttpBTXJYfNjRmAP9AA3yKNA/WpbnzNdzBlFIlzedbMhB3/6j1A15yV4 UonWRf3I8ch+JvFuek+kuksWAund73On10BWjDMLdQLH+xlYRHFBT/otSKhjNcx++WMd 3KWVGqSFy+UKES1120gQvm8R7DBgttNuUmcyOYIBUfwa6jXuuv24lQhR6+Izezn1eNUz dLMw== 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=kO6usZ7dq/uMRXXSz5JM/8mIYAwe+rKw1TmPPq/bo00=; b=Fausamejv3x5SLgHCm+kEpd7RXqL3kSeVRQbNSBHE+pjZ1ui1A9fvINgb6RVnSVtaX 3euuaBvqQfBCI0nNLVLXuwUkpODdFrnwrVs/T330VAJPJrhAQ91563mWps2iJCX9cBaq QtZuZzbKgqMhEi+WfW0e65TLgkGuy81d6OAoo9CzzAoVG5UPu9/Ea7fiVIvFypixS7VN BMY1VxYP/qVQX6Qn1vkFo/zIxzOpBerlNeJSAnj3h5Yzqjdx0FHBQn335kTZBKTqK+z5 gIuZP3HKxL9Kj7yofF2h3myGZ2Xi2Bv0foyA6yrQN11tE02636oVfU4gxl0KtBHlqyZz pmxQ== 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 zm17si1581129ejb.712.2021.08.17.01.25.08; Tue, 17 Aug 2021 01:25:34 -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 S239156AbhHQIYL (ORCPT + 99 others); Tue, 17 Aug 2021 04:24:11 -0400 Received: from mga07.intel.com ([134.134.136.100]:11537 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239136AbhHQIYK (ORCPT ); Tue, 17 Aug 2021 04:24:10 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10078"; a="279763173" X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="279763173" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2021 01:23:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="471080188" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga008.jf.intel.com with ESMTP; 17 Aug 2021 01:23:35 -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 v11 02/24] tools lib: Introduce fdarray duplicate function Date: Tue, 17 Aug 2021 11:23:05 +0300 Message-Id: <6d345e29018ba6b203a9122638e0d006de0c8730.1629186429.git.alexey.v.bayduraev@linux.intel.com> 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 duplicate an existing file descriptor in the fdarray structure. The function returns the position of the duplicated file descriptor. Acked-by: Namhyung Kim Reviewed-by: Riccardo Mancini Tested-by: Riccardo Mancini 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..f0f195207fca 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__dup_entry_from(struct fdarray *fda, int pos, struct fdarray *from) +{ + struct pollfd *entry; + int npos; + + if (pos >= from->nr) + return -EINVAL; + + entry = &from->entries[pos]; + + npos = fdarray__add(fda, entry->fd, entry->events, from->priv[pos].flags); + if (npos >= 0) + fda->priv[npos] = from->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..60ad197c8ee9 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__dup_entry_from(struct fdarray *fda, int pos, struct fdarray *from); 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