Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1753062pxv; Fri, 2 Jul 2021 11:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyavaeuhEYifUHf53vEHLm1V29Kir2HJ/qH3YUMN/rqja2xvBfscz/mFcMGeXHgMoJJKFV2 X-Received: by 2002:a17:907:2ce2:: with SMTP id hz2mr1092352ejc.352.1625249819299; Fri, 02 Jul 2021 11:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625249819; cv=none; d=google.com; s=arc-20160816; b=qiNSAcxQ/5ZEHMDk4WGdd5ydk7swqPR69qTRtB0SNNWmII+5VIMKGZ899sbOdkMDco 8yB5czuSJZv5I0Aizf+w+fUFMecxdjijDR6P1vCicEnf/UOzVXJg9bptnRF+PlJtzHJw HW3GxyuEOyrkC0TPwQA7qp4q6pSWEia5WCN75vsRBMuBWROZsqgBRkOh1RKolk/Y2M/h Go6T7opE8+74rpuvzetWVYHuMH9qYAhznheJAwlDGXLBfyQezqNgzvMTprwyblHFWJSJ 3A8AXYhcczyBicyqRPJgS7EZWldltAZBUhNJYtf7JoLCpDQy0KRDY2w37sO1g0zPVNlR qZEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3f1liEKcxn7hpQUfUdlD+7FYMWtcrlZeeCHM6+yS4YA=; b=Vjzrb3E79YtiKzOPocLRXDMS39rBGj/oQ/+/3Uv58lqkwetSRmsrzDbv9jtF5Cd9og MC9l582L6duHOChKbD5xyfi6widHMJ1G9j5koBgY2xNUyoQCWQwFZOQdB5LwPZLVClW0 pdXU7gRWwFRmNvocywc45DVK2yPvHspr8vOoQVh/dS2l3grPHDZf4SdrVUxj9Wxaz3pS fO0Ybk8ga9O4VcDqphVY38j+pYYjqPO/anKesuRDbBO8ojIOVTSTriH+m+AQgZi7i+ix II3UhUmoyiQGtgfT6kASmm1ffLgAQ84A5CsUbkfIgLv7pWuxge31hgFGQ7UkAvc1OfE6 sPwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JjLJpNEy; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s2si360613ejs.611.2021.07.02.11.16.35; Fri, 02 Jul 2021 11:16:59 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JjLJpNEy; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbhGBSSR (ORCPT + 99 others); Fri, 2 Jul 2021 14:18:17 -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