From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 28B191FF0AA for ; Mon, 07 Sep 2026 15:03:48 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7A4DF2153C; Mon, 07 Sep 2026 15:03:47 +0200 (CEST) Message-ID: Date: Mon, 7 Sep 2026 15:03:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH proxmox-backup v2 06/10] tape: tape block: represent tape block header with its own struct To: "Max R. Carrara" References: <20260821140238.615302-1-m.carrara@proxmox.com> <20260821140238.615302-7-m.carrara@proxmox.com> <178836583425.294173.2400215559678666219.b4-review@b4> Content-Language: en-US, de-AT From: Robert Obkircher In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788786216036 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.594 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ARAZMCPZUDZHAOAS26VWJ2PHV6KIKFBS X-Message-ID-Hash: ARAZMCPZUDZHAOAS26VWJ2PHV6KIKFBS X-MailFrom: r.obkircher@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pbs-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 07.09.26 13:44, Max R. Carrara wrote: > On Wed Sep 2, 2026 at 6:17 PM CEST, Robert Obkircher wrote: >>> [..] >>> >>> + /// Returns the entirety of the tape block, meaning both its header and data >>> + /// payload, as a byte slice. >>> + pub fn as_bytes(&self) -> &[u8] { >>> + // SAFETY: >>> + // - Since `self` is a reference, we can convert it to a pointer without >>> + // any concerns. The resulting pointer is always valid and non-null. >> This point doesn't seem worth mentioning, especially if you leave out >> the more important ones like the fact that the struct doesn't contain >> any (uninitialized) padding bytes or interior mutability. > Good point, will add in v2. Thanks! > >>> + // - The pointer used here is not used or aliased anywhere else. >> This is neither true nor relevant. e.g. if you call as_bytes twice it >> will be aliased. > Right, but I was referring to the pointer that is `self as *const _` (or > `self as *mut _`) -- that pointer specifically is not aliased anywhere > else, meaning that the returned references are always valid and respect > Rust's ownership model. > > All that being said, I should probably rephrase this to be more precise. > Thanks a lot, will fix in v2! I still don't understand what you mean by "not aliased". For &mut self you can argue that you have exclusive access, but for &self you have to assume that other references exist. >>> + // - We allocated `*self` with a total size of `Self::SIZE` earlier, >>> + // meaning that the resulting slice never goes out of bounds. >> Relying on the fact that no other constructor exists seems like a bad >> idea. Just use `size_of_val(self)`. > Good point actually, since we just return a byte slice. Didn't think of > that. Will fix in v2, thanks! > >>> + // - The resulting slice never outlives `self`. >>> + unsafe { std::slice::from_raw_parts((self as *const _) as *const u8, Self::SIZE) } >> I'd prefer `ptr::from_ref(self).cast()` to avoid the _ > ACK, will fix in v2. Thanks! >