Re: [PATCH v2 2/3] mm/swap: use swap_ops to register swap device's methods

From: Baoquan He

Date: Wed Apr 08 2026 - 02:11:22 EST


On 03/30/26 at 08:30pm, Chris Li wrote:
......
> > @@ -608,6 +593,39 @@ static void swap_read_folio_bdev_async(struct folio *folio,
> > submit_bio(bio);
> > }
> >
> > +static const struct swap_ops bdev_fs_swap_ops = {
> > + .read_folio = swap_read_folio_fs,
> > + .write_folio = swap_writepage_fs,
> > +};
> > +
> > +static const struct swap_ops bdev_sync_swap_ops = {
> > + .read_folio = swap_read_folio_bdev_sync,
> > + .write_folio = swap_writepage_bdev_sync,
> > +};
> > +
> > +static const struct swap_ops bdev_async_swap_ops = {
> > + .read_folio = swap_read_folio_bdev_async,
> > + .write_folio = swap_writepage_bdev_async,
> > +};
> > +
> > +void setup_swap_ops(struct swap_info_struct *sis)
>
> setup_swap_ops()` needs to return an indication of an error.
> The error is that sis->ops is NULL or op->read_folio == NULL or
> op->write_folio == NULL.
> If there is an error, we should fail the swapon.

Thanks for your comments.

In the current patches, there's no chance any of these happens:
sis->ops is NULL or
op->read_folio == NULL or
op->write_folio == NULL

Because it's a if-else logic in setup_swap_ops(), adding an error
checking looks a little weird. I think it's worth adding the error
checking in setup_swap_ops() later when we have new swap_ops added
and there's potential any of above three cases could happen.

What do you think?

Thanks
Baoquan