From: Filip Schauer <f.schauer@proxmox.com>
To: Fiona Ebner <f.ebner@proxmox.com>,
Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH common v2 1/2] add get_device_stat helper subroutine
Date: Tue, 16 Apr 2024 11:28:49 +0200 [thread overview]
Message-ID: <93309f0f-fc45-47a7-9eaf-0834d2608b86@proxmox.com> (raw)
In-Reply-To: <c3af7312-6e9d-48f6-9641-67e3efc81efa@proxmox.com>
Patch v3 is available:
https://lists.proxmox.com/pipermail/pve-devel/2024-April/062989.html
On 15/04/2024 15:54, Fiona Ebner wrote:
> Am 15.04.24 um 15:17 schrieb Filip Schauer:
>> The get_device_stat subroutine gets a device path, validates it, and
>> returns the file mode and the device identifier.
>>
>> Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
>> ---
>> src/PVE/Tools.pm | 18 +++++++++++++++++-
>> 1 file changed, 17 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
>> index 766c809..d1b53e5 100644
>> --- a/src/PVE/Tools.pm
>> +++ b/src/PVE/Tools.pm
>> @@ -7,7 +7,8 @@ use Date::Format qw(time2str);
>> use Digest::MD5;
>> use Digest::SHA;
>> use Encode;
>> -use Fcntl qw(:DEFAULT :flock);
>> +use Errno qw(ENOENT);
> We already have "use POSIX" with various error codes, so should be added
> there.
>
>> +use Fcntl qw(:DEFAULT :flock :mode);
>> use File::Basename;
>> use File::Path qw(make_path);
>> use Filesys::Df (); # don't overwrite our df()
>> @@ -1853,6 +1854,21 @@ sub dev_t_minor($) {
>> return (($dev_t >> 12) & 0xfff00) | ($dev_t & 0xff);
>> }
>>
>> +sub get_device_stat {
> It's not the whole stat, so the name is a bit misleading. Tools.pm is
> already very big and mixes different things, so not super happy about
> adding new things to it. If it would return the whole stat, it could
> still be fine IMHO, because it's more likely to be reusable later.
> Alternatively, we can keep this code in pve-container.
>
>> + my ($path) = @_;
>> +
>> + die "Path is not defined\n" if !defined($path);
>> +
>> + my ($mode, $rdev) = (stat($path))[2, 6];
>> + die "Device $path does not exist\n" if $! == ENOENT;
>> + die "Error accessing device $path\n"
>> + if (!defined($mode) || !defined($rdev));
>> + die "$path is not a device\n"
>> + if (!S_ISBLK($mode) && !S_ISCHR($mode));
> Style nit: useless parentheses, post-if can fit on the same line.
>
>> +
>> + return ($mode, $rdev);
>> +}
>> +
>> # Given an array of array refs [ \[a b c], \[a b b], \[e b a] ]
>> # Returns the intersection of elements as a single array [a b]
>> sub array_intersect {
next prev parent reply other threads:[~2024-04-16 9:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 13:17 [pve-devel] [PATCH common/container v2 0/2] fix invalid device passthrough being added to config Filip Schauer
2024-04-15 13:17 ` [pve-devel] [PATCH common v2 1/2] add get_device_stat helper subroutine Filip Schauer
2024-04-15 13:54 ` Fiona Ebner
2024-04-16 9:28 ` Filip Schauer [this message]
2024-04-15 13:17 ` [pve-devel] [PATCH container v2 2/2] fix invalid device passthrough being added to config Filip Schauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=93309f0f-fc45-47a7-9eaf-0834d2608b86@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox