From: "Max Carrara" <m.carrara@proxmox.com>
To: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH v1 pve-storage 6/8] pluginbase: document image operation methods
Date: Thu, 03 Apr 2025 16:05:21 +0200 [thread overview]
Message-ID: <D8X27G1FDP6J.1QVHV5BNCVU2L@proxmox.com> (raw)
In-Reply-To: <1743664476.2gt96bhyxx.astroid@yuna.none>
On Thu Apr 3, 2025 at 9:23 AM CEST, Fabian Grünbichler wrote:
> On April 2, 2025 6:32 pm, Max Carrara wrote:
> > On Mon Mar 31, 2025 at 5:12 PM CEST, Fabian Grünbichler wrote:
> >> On March 26, 2025 3:20 pm, Max Carrara wrote:
> >> > Add documentation for the following methods:
> >> > - list_images
> >> > - create_base
> >> > - clone_image
> >> > - alloc_image
> >> > - free_image
> >> >
> >> > Signed-off-by: Max Carrara <m.carrara@proxmox.com>
> >> > Co-authored-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> >> > ---
> >> > src/PVE/Storage/PluginBase.pm | 111 ++++++++++++++++++++++++++++++++++
> >> > 1 file changed, 111 insertions(+)
> >> >
> >> > diff --git a/src/PVE/Storage/PluginBase.pm b/src/PVE/Storage/PluginBase.pm
> >> > index b3ce684..37b1471 100644
> >> > --- a/src/PVE/Storage/PluginBase.pm
> >> > +++ b/src/PVE/Storage/PluginBase.pm
> >> > @@ -721,26 +721,137 @@ sub on_delete_hook {
> >> >
> >> > =cut
> >> >
> >> > +=head3 $plugin->list_images($storeid, \%scfg [, $vmid, \@vollist, \%cache])
> >> > +
> >> > +B<REQUIRED:> Must be implemented in every storage plugin.
> >> > +
> >> > +Returns a listref of all disk images of a storage. If the storage does not
> >> > +support storing disk images, returns an empty listref.
> >> > +
> >> > +Optionally, if C<\@vollist> is provided, return only disks whose volume ID is
> >> > +within C<\@vollist>. Note that this usually has higher precedence than
> >> > +C<$vmid>.
> >
> > Upfront note: Unless I otherwise comment something, I agree with you.
> > Just sparing myself from writing and you from reading too many ACKs :P
> >
> >>
> >> what does usually mean? what does $vmid do?
> >
> > Sorry, this got lost when tossing out some redundant paragraphs here.
> >
> > The "usually" can be dropped; C<$vmid> is the guest's ID (mentioned in
> > the DESCRIPTION in patch 01) and unless C<\@vollist> is provided, the
> > images that the given C<$vmid> owns will be returned.
>
> in case that wasn't obvious - I know what $vmid is (and also what it
> does) - it should be explained to readers that don't (yet).
>
> So I think this should say something like:
>
> If C<$vmid> is set, only images owned by that VMID must be included in
> the return value.
>
> If C<\@vollist> is set and not empty, the return value must be filtered
> using the contained volids.
>
> If both C<$vmid> and C<\@vollist> are set, only C<\@vollist> should be
> honored.
Thanks for the suggestion, that's actually much better. I also agree
with the other suggestions further below.
>
> and about that last part - do we actually have callers that set both? if
> not, should we instead recommend treating it as an error and document it
> as such?
I'll revisit the call sites again and see whether we actually do, just
to be sure. The current code at least doesn't treat it as an error.
>
> >> > +
> >> > +C<die>s in case of errors.
> >> > +
> >> > +This method may reuse L<< cached information via C<\%cache>|/"CACHING EXPENSIVE OPERATIONS" >>.
> >> > +
> >> > +The returned listref has the following structure:
> >> > +
> >> > + [
> >> > + {
> >> > + ctime => "1689163322", # creation time as unix timestamp
> >> > + format => "raw",
> >> > + size => 8589934592, # in bytes!
> >> > + vmid => 101,
> >> > + volid => "local-lvm:base-101-disk-0", # volume ID, storage-specific
> >> > + },
> >> > + # [...]
> >> > + ]
> >> > +
> >> > +=cut
> >> > +
> >> > sub list_images {
> >> > my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
> >> > croak "implement me in sub-class\n";
> >> > }
> >> >
> >> > +=head3 $plugin->create_base($storeid, \%scfg, $volname)
> >> > +
> >> > +B<OPTIONAL:> May be implemented in a storage plugin.
> >> > +
> >> > +Creates a base volume from an existing volume, allowing the volume to be
> >>
> >> this is misleading - it doesn't create a base volume from an existing
> >> volume, it *converts* an existing volume into a base volume!
> >
> > Oh dang, thanks for pointing this out! Sorry for the oversight.
> >
> >>
> >> > +L<< cloned|/"$plugin->clone_image(...)" >>. This cloned volume (usually
> >> > +a disk image) may then be used as a base for the purpose of creating linked
> >>
> >> this is wrong? there is no cloned volume yet? and all of this only
> >> applies to images and not other volumes?
> >>
> >> > +clones. See L<C<PVE::Storage::LvmThinPlugin>> and
> >> > +L<C<PVE::Storage::ZFSPoolPlugin>> for example implementations.
> >> > +
> >> > +On completion, returns the name of the new base volume (the new C<$volname>).
> >> > +
> >> > +This method is called in the context of C<L<< cluster_lock_storage()|/"cluster_lock_storage(...)" >>>,
> >> > +i.e. when the storage is B<locked>.
> >>
> >> Shouldn't this say that it *should* be called in a locked context?
> >>
> >> > +
> >> > +=cut
> >> > +
> >> > sub create_base {
> >> > my ($class, $storeid, $scfg, $volname) = @_;
> >> > croak "implement me in sub-class\n";
> >> > }
> >> >
> >> > +=head3 $plugin->clone_image($scfg, $storeid, $volname, $vmid [, $snap])
> >> > +
> >> > +=head3 $plugin->clone_image(...)
> >> > +
> >> > +B<REQUIRED:> Must be implemented in every storage plugin.
> >>
> >> not really? there's a feature guard for it, so only storage plugins that
> >> support it should ever get it called anyway..
> >>
> >> what does $vmid mean?
> >
> > See above; the guest's ID. Since it was unclear, the parameter should
> > probably be explained here (and also above) instead of (just) in the
> > DESCRIPTION section.
>
> I know what a vmid is ;) the question is what does this parameter *mean*
> for this particular method?
>
> C<$vmid> contains the owner of the new volume, which must be encoded in
> the returned volid.
>
> or something like that?
>
> >> > +
> >> > +Clones a disk image or a snapshot of an image, returning the name of the new
> >> > +image (the new C<$volname>). Note that I<cloning> here means to create a linked
> >> > +clone and not duplicating an image. See L<C<PVE::Storage::LvmThinPlugin>> and
> >> > +L<C<PVE::Storage::ZFSPoolPlugin>> for example implementations.
> >>
> >> then why not start with
> >>
> >> "Creates a linked clone of an existing disk image or snapshot of an
> >> image"
> >>
> >> ? maybe also include that unless the linked clone is 100% independent
> >> from the base (only true for LVM thin atm?), the new volid should encode
> >> the base->clone relation in the volname?
> >>
> >> > +
> >> > +C<die>s in case of an error of if the underlying storage doesn't support
> >>
> >> s/of/or/
> >>
> >> > +cloning images.
> >> > +
> >> > +This method is called in the context of C<L<< cluster_lock_storage()|/"cluster_lock_storage(...)" >>>,
> >> > +i.e. when the storage is B<locked>.
> >>
> >> same as above
> >>
> >> > +
> >> > +=cut
> >> > +
> >> > sub clone_image {
> >> > my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
> >> > croak "implement me in sub-class\n";
> >> > }
> >> >
> >> > +=head3 $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size)
> >> > +
> >> > +B<REQUIRED:> Must be implemented in every storage plugin.
> >> > +
> >> > +Allocates a disk image with the given format C<$fmt> and C<$size> in bytes,
> >> > +returning the name of the new image (the new C<$volname>). See
> >> > +C<L<< plugindata()|/"$plugin->plugindata()" >>> for all disk formats.
> >> > +
> >> > +Optionally, if given, set the name of the image to C<$name>. If C<$name> isn't
> >> > +provided, the next name should be determined via C<L<< find_free_diskname()|/"$plugin->find_free_diskname(...)" >>>.
> >>
> >> a suitable name should be automatically generated, unless we really want
> >> to stabilize find_free_diskname as part of the API..
> >>
> >> what does $vmid mean?
>
> here as well, similar to clone_image above
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-04-03 14:05 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 14:20 [pve-devel] [PATCH v1 pve-storage 0/8] Base Module + Documentation for PVE::Storage::Plugin API Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 1/8] pluginbase: introduce PVE::Storage::PluginBase with doc scaffold Max Carrara
2025-03-31 15:13 ` Fabian Grünbichler
2025-04-02 16:31 ` Max Carrara
2025-04-03 7:12 ` Fabian Grünbichler
2025-04-03 14:05 ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 2/8] pluginbase: add high-level plugin API description Max Carrara
2025-03-31 15:13 ` Fabian Grünbichler
2025-04-02 16:31 ` Max Carrara
2025-04-03 7:12 ` Fabian Grünbichler
2025-04-03 14:05 ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 3/8] pluginbase: document SectionConfig methods Max Carrara
2025-03-31 15:13 ` Fabian Grünbichler
2025-04-02 16:31 ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 4/8] pluginbase: document general plugin methods Max Carrara
2025-03-28 12:50 ` Maximiliano Sandoval
2025-03-31 15:12 ` Fabian Grünbichler
2025-04-02 16:31 ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 5/8] pluginbase: document hooks Max Carrara
2025-03-28 13:07 ` Maximiliano Sandoval
2025-03-31 15:12 ` Fabian Grünbichler
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 6/8] pluginbase: document image operation methods Max Carrara
2025-03-31 15:12 ` Fabian Grünbichler
2025-04-02 16:32 ` Max Carrara
2025-04-03 7:23 ` Fabian Grünbichler
2025-04-03 14:05 ` Max Carrara [this message]
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 7/8] pluginbase: document volume operations Max Carrara
2025-03-31 15:12 ` Fabian Grünbichler
2025-04-02 16:32 ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 8/8] pluginbase: document import and export methods Max Carrara
2025-04-01 8:40 ` Fabian Grünbichler
2025-04-01 9:40 ` Fiona Ebner
2025-04-02 16:32 ` Max Carrara
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=D8X27G1FDP6J.1QVHV5BNCVU2L@proxmox.com \
--to=m.carrara@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal