From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 386B3C07E95 for ; Fri, 2 Jul 2021 18:15:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 179036140E for ; Fri, 2 Jul 2021 18:15:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbhGBSSS (ORCPT ); Fri, 2 Jul 2021 14:18:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:56228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbhGBSSR (ORCPT ); Fri, 2 Jul 2021 14:18:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 02EF8613DC; Fri, 2 Jul 2021 18:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625249745; bh=0PGfeLOVIYY2WpcoibguCgA2At0IRQvLGVRHR7AppB4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JjLJpNEy0ZjKRZ4DXwAjerVDqKZJTWLAReg1mUdHG6Om3AlauS8ui+M4gjF+8DsmC CnAacGXtl4fhasawY+/E3orpxIU4MnkqIQGBn8s/Bb+kqZccmAeaXMoRQ/VJ3pbOx3 +0k3SjpLkbAxbIhQN+ys8qMJRyUWzOzqD+kvBT2rOp5S5jsuIIMMqU96pbZ2p/4oWQ cTGX5mYTfU3Ntkog27L906h3HAZdaYggUwdwdztD4rK/GKBtOjofKmmbs2OkhfCwmJ 9Khv40qanG0G/JDdyWigidXr38w31rsTX+HGvxU0BqhiUQ/oxI7QGQuEw01+Pq4lb4 viz0yNuPKJn5Q== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 200F340B1A; Fri, 2 Jul 2021 15:15:42 -0300 (-03) Date: Fri, 2 Jul 2021 15:15:42 -0300 From: Arnaldo Carvalho de Melo To: Alexey Bayduraev Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: Re: [PATCH v9 02/24] tools lib: Introduce fdarray clone function Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Jul 02, 2021 at 03:32:10PM +0300, Alexey Bayduraev escreveu: > 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) The "XX__clone" idiom means "get the XXX instance and get me a clone of it", i.e. of the whole class, not of an entry, see map__clone(), evsel__clone(), parse_events_term__clone(), etc. Please consider: int fdarray__dup_entry_from(struct fdarray *fda, int pos, struct fdarray *from) > +{ > + 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 > -- - Arnaldo