From patchwork Wed May 8 11:04:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658539 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF1E681729 for ; Wed, 8 May 2024 11:04:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166247; cv=none; b=S13OC0Os9rv5VO8WY+455+0g9egGZVRoT2VvvaJfSoJFw/r0LF5QhFDKggrluvUONkH4H9ZbZJHpGPTvn1OISwyaT5OVEl1G9hSCWIGv55kEmnnyh1h6mAA7nA9dhgCAMI+wwRU0fsZqDagFyoI+BrxeBD+SE5XRXgnFHIT5Ekg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166247; c=relaxed/simple; bh=SjQmixg0I5BolOZDDQZTKLfLIYeGvgGglmWn8wHuBPs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TK4YCud53Hw/DtLZBCcBCiBhBcvfWx/TaGLpkm+XpgdRN1cCNXI2OuyVYdrIO+/0II58Nk0AV0kfBql9PUcI+/71oKWD+riRmF5AI8p1TMDWVoEJpi5D/g/6eKoPvxzPIVwcjEmKxHSSXom+ZFQ4KjA28pxYU3n8lq66gQOL2Zg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=VGeM0OyE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Trc0EOVv; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="VGeM0OyE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Trc0EOVv" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 917CD1140226 for ; Wed, 8 May 2024 07:04:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 08 May 2024 07:04:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715166244; x=1715252644; bh=O1dnZy4VQ5 p78DneuAJe9CzVH9xMYTUrJOwkbGgNcx8=; b=VGeM0OyEsfO2dXH/TSmLb+tu9z LHQGeECcnx5t21475BXQa/lXz3j5Usd96ux/GEuBpH0o/PsXTmLXniNCYvcV+/y1 nf+D7mncvG/AW7URheiiUpMBpPmCYG0wpVJ85M1wAnKsQtenWcnIEHiHoPs71wnU mjDFcRGA+vS0D8qbnfA8mrfbk/u2XoClfZkeUY+3Lw9IVaU5KCnQxj7s9pcfh2/c xVhjmtwp484tkdDndCqWAA8JSysiIsbFTVdrxHbNUD8RCGfbSp9oXWtOW9n4qrpz bMJMh54feRi/hwaTCEFgFo36iLRA+XUTkQt4/Rupf7w3ZoC7xLKuzjqamjBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715166244; x=1715252644; bh=O1dnZy4VQ5p78DneuAJe9CzVH9xM YTUrJOwkbGgNcx8=; b=Trc0EOVvGDy4LTqXXeMXWDgFqTLP+dKKYkyzWOaUfBzY YbhjXorrXQ4C05zrdTLLWdekBqNgwKU0A3vjGKOjocpNaIUkub/aKwaB/Tjoal7d t6Gmmru30fZu++xH3u+bYY5j7Xq/yylRnyniRa3LRUgDge1quvAXt88skbtYOdcZ ZsoKoEIN1Q2nzfv8wq63wLIOsWA2rBKXrZAPuHD8H39a48lmWIeeQfBlbU24MIi2 jI3D20w5iTDYBK77359ayl5usZIuJXWh3s6kMudQE+MJqqLxaU2eBfag6KOLY4nP mO1cwnAqu3UFECTzWTRagJtF1KlKrRlkyIEpQWyfLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:03 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c7777124 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:54 +0000 (UTC) Date: Wed, 8 May 2024 13:04:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/13] reftable/reader: set up the reader when initializing table iterator Message-ID: <5a10a115841512a46e4d3a3d3713e5532facdb39.1715166175.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: All the seeking functions accept a `struct reftable_reader` as input such that they can use the reader to look up the respective blocks. Refactor the code to instead set up the reader as a member of `struct table_iter` during initialization such that we don't have to pass the reader on every single call. This step is required to move seeking of records into the generic `struct reftable_iterator` infrastructure. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index c3541e2c43..021608f638 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -224,8 +224,14 @@ struct table_iter { struct block_iter bi; int is_finished; }; -#define TABLE_ITER_INIT { \ - .bi = BLOCK_ITER_INIT \ + +static int table_iter_init(struct table_iter *ti, struct reftable_reader *r) +{ + struct block_iter bi = BLOCK_ITER_INIT; + memset(ti, 0, sizeof(*ti)); + ti->r = r; + ti->bi = bi; + return 0; } static int table_iter_next_in_block(struct table_iter *ti, @@ -386,26 +392,23 @@ static void iterator_from_table_iter(struct reftable_iterator *it, it->ops = &table_iter_vtable; } -static int table_iter_seek_to(struct table_iter *ti, struct reftable_reader *r, - uint64_t off, uint8_t typ) +static int table_iter_seek_to(struct table_iter *ti, uint64_t off, uint8_t typ) { int err; - err = reader_init_block_reader(r, &ti->br, off, typ); + err = reader_init_block_reader(ti->r, &ti->br, off, typ); if (err != 0) return err; - ti->r = r; ti->typ = block_reader_type(&ti->br); ti->block_off = off; block_iter_seek_start(&ti->bi, &ti->br); return 0; } -static int table_iter_seek_start(struct table_iter *ti, struct reftable_reader *r, - uint8_t typ, int index) +static int table_iter_seek_start(struct table_iter *ti, uint8_t typ, int index) { - struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); + struct reftable_reader_offsets *offs = reader_offsets_for(ti->r, typ); uint64_t off = offs->offset; if (index) { off = offs->index_offset; @@ -415,7 +418,7 @@ static int table_iter_seek_start(struct table_iter *ti, struct reftable_reader * typ = BLOCK_TYPE_INDEX; } - return table_iter_seek_to(ti, r, off, typ); + return table_iter_seek_to(ti, off, typ); } static int table_iter_seek_linear(struct table_iter *ti, @@ -548,7 +551,7 @@ static int table_iter_seek_indexed(struct table_iter *ti, if (err != 0) goto done; - err = table_iter_seek_to(ti, ti->r, index_result.u.idx.offset, 0); + err = table_iter_seek_to(ti, index_result.u.idx.offset, 0); if (err != 0) goto done; @@ -578,7 +581,7 @@ static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it, { uint8_t typ = reftable_record_type(rec); struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); - struct table_iter ti = TABLE_ITER_INIT, *p; + struct table_iter ti, *p; int err; if (!offs->is_present) { @@ -586,7 +589,9 @@ static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it, return 0; } - err = table_iter_seek_start(&ti, r, reftable_record_type(rec), + table_iter_init(&ti, r); + + err = table_iter_seek_start(&ti, reftable_record_type(rec), !!offs->index_offset); if (err < 0) goto out; @@ -722,15 +727,15 @@ static int reftable_reader_refs_for_unindexed(struct reftable_reader *r, struct reftable_iterator *it, uint8_t *oid) { - struct table_iter ti_empty = TABLE_ITER_INIT; - struct table_iter *ti = reftable_calloc(1, sizeof(*ti)); + struct table_iter *ti; struct filtering_ref_iterator *filter = NULL; struct filtering_ref_iterator empty = FILTERING_REF_ITERATOR_INIT; int oid_len = hash_size(r->hash_id); int err; - *ti = ti_empty; - err = table_iter_seek_start(ti, r, BLOCK_TYPE_REF, 0); + REFTABLE_ALLOC_ARRAY(ti, 1); + table_iter_init(ti, r); + err = table_iter_seek_start(ti, BLOCK_TYPE_REF, 0); if (err < 0) { reftable_free(ti); return err;