Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3374030pxb; Mon, 17 Jan 2022 18:57:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/CM2yNL48pTBwg2iTePb5KQTG2sXMMU05lccY1VZu7p6H6sb5OY9ktqOW/qJ1Q9vjnsIy X-Received: by 2002:a05:6a00:998:b0:4c4:455:cebc with SMTP id u24-20020a056a00099800b004c40455cebcmr8734647pfg.67.1642474678296; Mon, 17 Jan 2022 18:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642474678; cv=none; d=google.com; s=arc-20160816; b=wDUmc3nSvH/I05Yexsa03EL+cinM0Rya5qa+l7CtKQCbw4aS6EBqx5nVtuJgP7sMQ/ 4REh99ZqkqDCZpJjbGGCMbuzxnNEkLmhoCuFnYgonfhSAHIPUxq4DQco4hSj+nGafmAY YV3EHDhB+C8WXNvm2waBmja6JYWOBsHXIRLwXcHJBwayn93UZTO0ytlmRzQ94Krpkd4F UBwVO7jwtIQVlM07OxTThvL/8MarCWvkQ8A+XDExlxRUtg2qSXVmyD7w+7YLWHFOstfM WsA9bZm+PUE1lQHm1gE9djJo0pP4bkw52bNvXhl8Z14ACoqHgYQJl0BGv/iJ761N+Y5w W9AA== 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 :dkim-signature; bh=kO6usZ7dq/uMRXXSz5JM/8mIYAwe+rKw1TmPPq/bo00=; b=N9xw8h6sglDmapDjkhk0Zd4YSLXaNLL6g+iFkaPC15uF3sZyKDm9w+8DqkaWG1IG43 pJeQtxIBmAmCBE1T+Z+I25RxETUskGLTs2XJzVVXUNiZ3xoPHlbHgam98Ez+7QbJMzMr YhjbZV//7IGTc00CpQ+NtYGD3tzXzAn2xEwGK/y85Cn5SPm6cCiqyBD1W1E7V5khsHfh gZk3n80YmBSBsq+g3slUumEyFyYX8dYticCTyVaTaXJZiVvzKoH78urkkGornl5m7N9r errfy6z1OkyPFOfWKiaIIdx28oan89gNXJNDEvzWLQfjihM+3tAMPA68QM2kFCI/i1J0 AOQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DjtOYLva; 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=pass (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 d5si1884707plr.458.2022.01.17.18.57.46; Mon, 17 Jan 2022 18:57:58 -0800 (PST) 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; dkim=pass header.i=@intel.com header.s=Intel header.b=DjtOYLva; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233561AbiAQSga (ORCPT + 99 others); Mon, 17 Jan 2022 13:36:30 -0500 Received: from mga12.intel.com ([192.55.52.136]:48606 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242628AbiAQSer (ORCPT ); Mon, 17 Jan 2022 13:34:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642444486; x=1673980486; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mYkC69QeVaw1eSEJY4L24VYYn4aS7wkr+OUnrytuVIU=; b=DjtOYLva9X6VyJYYucFBN4oUD1nvVf9Y9JZmbkH5a80TVoI3mDyGrilM GCkkFZeCFMfeiJtSYV2i6mxaTF1veZC2wNq6Z5Uol1td9cl1Nfw76L8rK IOHDHdU1us3LZxRk27YCBgx2qG6FNytfS1/QzVuDFTh9lEny1tnx2Obf+ MJHuHyq7PKkK5UiB1PNRtTvl64MPu0cG8o/AQ6ID2pMe4KxAmVTq38SN0 PfihSe5BZ3S/qbbue2nnR4PsiRMX3GaNDQvi5arVyQaNbiTXtUcUOyIja 4YyPOg48auHxca8P7OttG3I0f+cTzr4tfCKPdrZJzEXjxkhOKjRL2Wf30 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10229"; a="224655971" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="224655971" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 10:34:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="492434184" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga002.jf.intel.com with ESMTP; 17 Jan 2022 10:34:43 -0800 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 v13 02/16] tools lib: Introduce fdarray duplicate function Date: Mon, 17 Jan 2022 21:34:22 +0300 Message-Id: <2891f1def287d5863cc82683a4d5879195c8d90c.1642440724.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