[3/4] ploop: allow to set discard granularity and alignment attributes

Submitted by Andrei Vagin on Feb. 15, 2018, 1:36 a.m.

Details

Message ID 1518658567-3659-3-git-send-email-avagin@openvz.org
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrei Vagin Feb. 15, 2018, 1:36 a.m.
[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

Different backing stores can have different values for these parameters.

Signed-off-by: Andrei Vagin <avagin@openvz.org>
---
 drivers/block/ploop/sysfs.c | 48 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

--
1.8.3.1

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
index acd18ff..835558a 100644
--- a/drivers/block/ploop/sysfs.c
+++ b/drivers/block/ploop/sysfs.c
@@ -362,6 +362,51 @@  static int store_aborted(struct ploop_device * plo, u32 val)
        return 0;
 }

+static u32 show_discard_granularity(struct ploop_device * plo)
+{
+       return plo->queue->limits.discard_granularity;
+}
+
+static int store_discard_granularity(struct ploop_device * plo, u32 val)
+{
+       int q = ilog2(val);
+
+       /* look at kaio_fill_zero_submit */
+       if (1 << q != val || val > PAGE_SIZE || val < 512)
+               return -EINVAL;
+
+       plo->queue->limits.discard_granularity = val;
+       return 0;
+}
+
+static u32 show_discard_alignment(struct ploop_device * plo)
+{
+       return plo->queue->limits.discard_alignment;
+}
+
+static int store_discard_alignment(struct ploop_device * plo, u32 val)
+{
+       int q = ilog2(val);
+
+       /* look at kaio_fill_zero_submit */
+       if (1 << q != val || val > PAGE_SIZE || val < 512)
+               return -EINVAL;
+
+       plo->queue->limits.discard_alignment = val;
+       return 0;
+}
+
+static u32 show_discard_zeroes_data(struct ploop_device * plo)
+{
+       return plo->queue->limits.discard_zeroes_data;
+}
+
+static int store_discard_zeroes_data(struct ploop_device * plo, u32 val)
+{
+       plo->queue->limits.discard_zeroes_data = !!val;
+       return 0;
+}
+
 static u32 show_top(struct ploop_device * plo)
 {
        int top = -1;
@@ -550,6 +595,9 @@  static struct attribute *state_attributes[] = {
        _A(blockable_reqs),
        _A(blocked_bios),
        _A(freeze_state),
+       _A2(discard_granularity),
+       _A2(discard_alignment),
+       _A2(discard_zeroes_data),
        NULL
 };


Comments

Konstantin Khorenko Feb. 16, 2018, 8:11 a.m.
On 02/15/2018 04:36 AM, Andrei Vagin wrote:
>
> Different backing stores can have different values for these parameters.
>
> Signed-off-by: Andrei Vagin <avagin@openvz.org>
> ---
>  drivers/block/ploop/sysfs.c | 48 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
>
> diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
> index acd18ff..835558a 100644
> --- a/drivers/block/ploop/sysfs.c
> +++ b/drivers/block/ploop/sysfs.c
> @@ -362,6 +362,51 @@ static int store_aborted(struct ploop_device * plo, u32 val)
>         return 0;
>  }
>
> +static u32 show_discard_granularity(struct ploop_device * plo)
> +{
> +       return plo->queue->limits.discard_granularity;
> +}
> +
> +static int store_discard_granularity(struct ploop_device * plo, u32 val)
> +{
> +       int q = ilog2(val);
> +
> +       /* look at kaio_fill_zero_submit */
> +       if (1 << q != val || val > PAGE_SIZE || val < 512)
> +               return -EINVAL;
> +
> +       plo->queue->limits.discard_granularity = val;
> +       return 0;
> +}
> +
> +static u32 show_discard_alignment(struct ploop_device * plo)
> +{
> +       return plo->queue->limits.discard_alignment;
> +}
> +
> +static int store_discard_alignment(struct ploop_device * plo, u32 val)
> +{
> +       int q = ilog2(val);
> +
> +       /* look at kaio_fill_zero_submit */
> +       if (1 << q != val || val > PAGE_SIZE || val < 512)
> +               return -EINVAL;
> +
> +       plo->queue->limits.discard_alignment = val;
> +       return 0;
> +}
> +
> +static u32 show_discard_zeroes_data(struct ploop_device * plo)
> +{
> +       return plo->queue->limits.discard_zeroes_data;
> +}
> +
> +static int store_discard_zeroes_data(struct ploop_device * plo, u32 val)
> +{
> +       plo->queue->limits.discard_zeroes_data = !!val;
> +       return 0;
> +}
> +
>  static u32 show_top(struct ploop_device * plo)
>  {
>         int top = -1;
> @@ -550,6 +595,9 @@ static struct attribute *state_attributes[] = {
>         _A(blockable_reqs),
>         _A(blocked_bios),
>         _A(freeze_state),
> +       _A2(discard_granularity),
> +       _A2(discard_alignment),
> +       _A2(discard_zeroes_data),
>         NULL
>  };

BTW, why these new parameters are state_attributes (others are readonly, except for "aborted"),
but not tune_attributes like other rw parameters?
Andrey Vagin Feb. 27, 2018, 10:31 p.m.
On Fri, Feb 16, 2018 at 11:11:54AM +0300, Konstantin Khorenko wrote:
> On 02/15/2018 04:36 AM, Andrei Vagin wrote:
> > 
> > Different backing stores can have different values for these parameters.
> > 
> > Signed-off-by: Andrei Vagin <avagin@openvz.org>
> > ---
> >  drivers/block/ploop/sysfs.c | 48 +++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 48 insertions(+)
> > 
> > diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
> > index acd18ff..835558a 100644
> > --- a/drivers/block/ploop/sysfs.c
> > +++ b/drivers/block/ploop/sysfs.c
> > @@ -362,6 +362,51 @@ static int store_aborted(struct ploop_device * plo, u32 val)
> >         return 0;
> >  }
> > 
> > +static u32 show_discard_granularity(struct ploop_device * plo)
> > +{
> > +       return plo->queue->limits.discard_granularity;
> > +}
> > +
> > +static int store_discard_granularity(struct ploop_device * plo, u32 val)
> > +{
> > +       int q = ilog2(val);
> > +
> > +       /* look at kaio_fill_zero_submit */
> > +       if (1 << q != val || val > PAGE_SIZE || val < 512)
> > +               return -EINVAL;
> > +
> > +       plo->queue->limits.discard_granularity = val;
> > +       return 0;
> > +}
> > +
> > +static u32 show_discard_alignment(struct ploop_device * plo)
> > +{
> > +       return plo->queue->limits.discard_alignment;
> > +}
> > +
> > +static int store_discard_alignment(struct ploop_device * plo, u32 val)
> > +{
> > +       int q = ilog2(val);
> > +
> > +       /* look at kaio_fill_zero_submit */
> > +       if (1 << q != val || val > PAGE_SIZE || val < 512)
> > +               return -EINVAL;
> > +
> > +       plo->queue->limits.discard_alignment = val;
> > +       return 0;
> > +}
> > +
> > +static u32 show_discard_zeroes_data(struct ploop_device * plo)
> > +{
> > +       return plo->queue->limits.discard_zeroes_data;
> > +}
> > +
> > +static int store_discard_zeroes_data(struct ploop_device * plo, u32 val)
> > +{
> > +       plo->queue->limits.discard_zeroes_data = !!val;
> > +       return 0;
> > +}
> > +
> >  static u32 show_top(struct ploop_device * plo)
> >  {
> >         int top = -1;
> > @@ -550,6 +595,9 @@ static struct attribute *state_attributes[] = {
> >         _A(blockable_reqs),
> >         _A(blocked_bios),
> >         _A(freeze_state),
> > +       _A2(discard_granularity),
> > +       _A2(discard_alignment),
> > +       _A2(discard_zeroes_data),
> >         NULL
> >  };
> 
> BTW, why these new parameters are state_attributes (others are readonly, except for "aborted"),
> but not tune_attributes like other rw parameters?

It was done by mistake. I have sent a fix. Thank you!