From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 5915A71023 for ; Mon, 17 May 2021 14:31:58 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 554032BB48 for ; Mon, 17 May 2021 14:31:58 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 8C1802BB3A for ; Mon, 17 May 2021 14:31:53 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 64F3443681 for ; Mon, 17 May 2021 14:31:53 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Mon, 17 May 2021 14:31:37 +0200 Message-Id: <20210517123137.25547-3-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210517123137.25547-1-s.reiter@proxmox.com> References: <20210517123137.25547-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 3/3] file-restore-daemon: disk: add RawFs bucket type X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 12:31:58 -0000 Used to specify a filesystem placed directly on a disk, without a partition table inbetween. Detected by simply attempting to mount the disk itself. A helper "make_dev_node" is extracted to avoid code duplication. Signed-off-by: Stefan Reiter --- src/bin/proxmox_restore_daemon/disk.rs | 68 +++++++++++++++++++------- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/src/bin/proxmox_restore_daemon/disk.rs b/src/bin/proxmox_restore_daemon/disk.rs index 8ad270fa..1ff5468f 100644 --- a/src/bin/proxmox_restore_daemon/disk.rs +++ b/src/bin/proxmox_restore_daemon/disk.rs @@ -62,6 +62,7 @@ struct PartitionBucketData { /// e.g.: "/drive-scsi0/part/0/etc/passwd" enum Bucket { Partition(PartitionBucketData), + RawFs(PartitionBucketData), } impl Bucket { @@ -79,12 +80,14 @@ impl Bucket { false } } + Bucket::RawFs(_) => ty == "raw", }) } fn type_string(&self) -> &'static str { match self { Bucket::Partition(_) => "part", + Bucket::RawFs(_) => "raw", } } @@ -100,19 +103,21 @@ impl Bucket { } Ok(match self { Bucket::Partition(data) => data.number.to_string(), + Bucket::RawFs(_) => "raw".to_owned(), }) } fn component_depth(type_string: &str) -> Result { Ok(match type_string { "part" => 1, + "raw" => 0, _ => bail!("invalid bucket type for component depth: {}", type_string), }) } fn size(&self) -> u64 { match self { - Bucket::Partition(data) => data.size, + Bucket::Partition(data) | Bucket::RawFs(data) => data.size, } } } @@ -145,8 +150,8 @@ impl Filesystems { fn ensure_mounted(&self, bucket: &mut Bucket) -> Result { match bucket { - Bucket::Partition(data) => { - // regular data partition à la "/dev/vdxN" + Bucket::Partition(data) | Bucket::RawFs(data) => { + // regular data partition à la "/dev/vdxN" or FS directly on a disk if let Some(mp) = &data.mountpoint { return Ok(mp.clone()); } @@ -197,6 +202,8 @@ pub struct DiskState { impl DiskState { /// Scan all disks for supported buckets. pub fn scan() -> Result { + let filesystems = Filesystems::scan()?; + // create mapping for virtio drives and .fidx files (via serial description) // note: disks::DiskManager relies on udev, which we don't have let mut disk_map = HashMap::new(); @@ -223,6 +230,25 @@ impl DiskState { } }; + // attempt to mount device directly + let dev_node = format!("/dev/{}", name); + let size = Self::make_dev_node(&dev_node, &sys_path)?; + let mut dfs_bucket = Bucket::RawFs(PartitionBucketData { + dev_node: dev_node.clone(), + number: 0, + mountpoint: None, + size, + }); + if let Ok(_) = filesystems.ensure_mounted(&mut dfs_bucket) { + // mount succeeded, add bucket and skip any other checks for the disk + info!( + "drive '{}' ('{}', '{}') contains fs directly ({}B)", + name, fidx, dev_node, size + ); + disk_map.insert(fidx, vec![dfs_bucket]); + continue; + } + let mut parts = Vec::new(); for entry in proxmox_backup::tools::fs::scan_subdir( libc::AT_FDCWD, @@ -232,32 +258,23 @@ impl DiskState { .filter_map(Result::ok) { let part_name = unsafe { entry.file_name_utf8_unchecked() }; - let devnode = format!("/dev/{}", part_name); + let dev_node = format!("/dev/{}", part_name); let part_path = format!("/sys/block/{}/{}", name, part_name); // create partition device node for further use - let dev_num_str = fs::file_read_firstline(&format!("{}/dev", part_path))?; - let (major, minor) = dev_num_str.split_at(dev_num_str.find(':').unwrap()); - Self::mknod_blk(&devnode, major.parse()?, minor[1..].trim_end().parse()?)?; + let size = Self::make_dev_node(&dev_node, &part_path)?; let number = fs::file_read_firstline(&format!("{}/partition", part_path))? .trim() .parse::()?; - // this *always* contains the number of 512-byte sectors, regardless of the true - // blocksize of this disk - which should always be 512 here anyway - let size = fs::file_read_firstline(&format!("{}/size", part_path))? - .trim() - .parse::()? - * 512; - info!( "drive '{}' ('{}'): found partition '{}' ({}, {}B)", - name, fidx, devnode, number, size + name, fidx, dev_node, number, size ); let bucket = Bucket::Partition(PartitionBucketData { - dev_node: devnode, + dev_node, mountpoint: None, number, size, @@ -266,11 +283,11 @@ impl DiskState { parts.push(bucket); } - disk_map.insert(fidx.to_owned(), parts); + disk_map.insert(fidx, parts); } Ok(Self { - filesystems: Filesystems::scan()?, + filesystems, disk_map, }) } @@ -381,6 +398,21 @@ impl DiskState { Ok(ResolveResult::Path(local_path)) } + fn make_dev_node(devnode: &str, sys_path: &str) -> Result { + let dev_num_str = fs::file_read_firstline(&format!("{}/dev", sys_path))?; + let (major, minor) = dev_num_str.split_at(dev_num_str.find(':').unwrap()); + Self::mknod_blk(&devnode, major.parse()?, minor[1..].trim_end().parse()?)?; + + // this *always* contains the number of 512-byte sectors, regardless of the true + // blocksize of this disk - which should always be 512 here anyway + let size = fs::file_read_firstline(&format!("{}/size", sys_path))? + .trim() + .parse::()? + * 512; + + Ok(size) + } + fn mknod_blk(path: &str, maj: u64, min: u64) -> Result<(), Error> { use nix::sys::stat; let dev = stat::makedev(maj, min); -- 2.20.1