diff mbox

[v4,2/4] generic: test mmap io fom DAX to non-DAX

Message ID 1492413255-11146-3-git-send-email-xzhou@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Murphy Zhou April 17, 2017, 7:14 a.m. UTC
Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
do mmap DIO from DAX to non-DAX.

This test is split from generic/413. Since DIO from DAX
to non-DAX is only supported/doable when device underneath
has memory(struct page) backend.

By ndctl looking at SCRATCH_DEV, skip this test if it is
not in "memory mode".

Adding helper to check pmem device status, which requires new
PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
JSON format outputs.

Signed-off-by: Xiong Zhou <xzhou@redhat.com>
---
 common/rc             |  45 ++++++++++++++++++++
 tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/423.out |   2 +
 tests/generic/group   |   1 +
 4 files changed, 161 insertions(+)
 create mode 100755 tests/generic/423
 create mode 100644 tests/generic/423.out

Comments

Dan Williams April 17, 2017, 2:14 p.m. UTC | #1
On Mon, Apr 17, 2017 at 12:14 AM, Xiong Zhou <xzhou@redhat.com> wrote:
> Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
> do mmap DIO from DAX to non-DAX.
>
> This test is split from generic/413. Since DIO from DAX
> to non-DAX is only supported/doable when device underneath
> has memory(struct page) backend.
>
> By ndctl looking at SCRATCH_DEV, skip this test if it is
> not in "memory mode".
>
> Adding helper to check pmem device status, which requires new
> PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
> JSON format outputs.
>
> Signed-off-by: Xiong Zhou <xzhou@redhat.com>
> ---
>  common/rc             |  45 ++++++++++++++++++++
>  tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/423.out |   2 +
>  tests/generic/group   |   1 +
>  4 files changed, 161 insertions(+)
>  create mode 100755 tests/generic/423
>  create mode 100644 tests/generic/423.out
>
> diff --git a/common/rc b/common/rc
> index 78a2101..73ac79c 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -3151,6 +3151,51 @@ _require_chattr()
>         rm -f $TEST_DIR/syscalltest.out
>  }
>
> +# Require test/scratch device nvdimm and having specific
> +# arttibute key/value we need.
> +#
> +# This is designed to get attr values of nvdimm persistent
> +# memory device, by searching sysfs.
> +#
> +# Other non-nvdimm or non-persistent-memory devices would
> +# fail this helper anyway.
> +#
> +# So, ONLY use this helper when you REALLY need nvdimm and
> +# specific attr on it.
> +#
> +_require_pmem_key_value()
> +{
> +       local dev=${1#/dev/}
> +       local key=$2
> +       local value=$3
> +       local region index keyfile dev_value
> +
> +       # find a filename string contains the region of dev, eg:
> +       #  /sys/devices/platform/e820_pmem/ndbus0/region1/\
> +       #  namespace1.0/block/pmem1
> +       #
> +       region=$(find /sys/ | grep $dev | grep region | head -1)
> +       [ -z "$region" ] && \
> +         _notrun "requires persistent memory $dev $key $value"

Running 'find' in sysfs is overkill. You can go directly to the sysfs
path for a given block device by stat(1) on the block device special
file to get the device major and minor numbers. Then go directly to
the sysfs path for that device by following this link
/sys/dev/block/$major:$minor.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Williams April 17, 2017, 10:54 p.m. UTC | #2
On Mon, Apr 17, 2017 at 7:14 AM, Dan Williams <dan.j.williams@intel.com> wrote:
> On Mon, Apr 17, 2017 at 12:14 AM, Xiong Zhou <xzhou@redhat.com> wrote:
>> Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
>> do mmap DIO from DAX to non-DAX.
>>
>> This test is split from generic/413. Since DIO from DAX
>> to non-DAX is only supported/doable when device underneath
>> has memory(struct page) backend.
>>
>> By ndctl looking at SCRATCH_DEV, skip this test if it is
>> not in "memory mode".
>>
>> Adding helper to check pmem device status, which requires new
>> PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
>> JSON format outputs.
>>
>> Signed-off-by: Xiong Zhou <xzhou@redhat.com>
>> ---
>>  common/rc             |  45 ++++++++++++++++++++
>>  tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>  tests/generic/423.out |   2 +
>>  tests/generic/group   |   1 +
>>  4 files changed, 161 insertions(+)
>>  create mode 100755 tests/generic/423
>>  create mode 100644 tests/generic/423.out
>>
>> diff --git a/common/rc b/common/rc
>> index 78a2101..73ac79c 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -3151,6 +3151,51 @@ _require_chattr()
>>         rm -f $TEST_DIR/syscalltest.out
>>  }
>>
>> +# Require test/scratch device nvdimm and having specific
>> +# arttibute key/value we need.
>> +#
>> +# This is designed to get attr values of nvdimm persistent
>> +# memory device, by searching sysfs.
>> +#
>> +# Other non-nvdimm or non-persistent-memory devices would
>> +# fail this helper anyway.
>> +#
>> +# So, ONLY use this helper when you REALLY need nvdimm and
>> +# specific attr on it.
>> +#
>> +_require_pmem_key_value()
>> +{
>> +       local dev=${1#/dev/}
>> +       local key=$2
>> +       local value=$3
>> +       local region index keyfile dev_value
>> +
>> +       # find a filename string contains the region of dev, eg:
>> +       #  /sys/devices/platform/e820_pmem/ndbus0/region1/\
>> +       #  namespace1.0/block/pmem1
>> +       #
>> +       region=$(find /sys/ | grep $dev | grep region | head -1)
>> +       [ -z "$region" ] && \
>> +         _notrun "requires persistent memory $dev $key $value"
>
> Running 'find' in sysfs is overkill. You can go directly to the sysfs
> path for a given block device by stat(1) on the block device special
> file to get the device major and minor numbers. Then go directly to
> the sysfs path for that device by following this link
> /sys/dev/block/$major:$minor.

Of course, this is all handled for you if you just use ndctl, so I'm
not sure what the motivation is to bypass those tools? They are widely
available.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ross Zwisler April 17, 2017, 11:39 p.m. UTC | #3
On Mon, Apr 17, 2017 at 03:54:30PM -0700, Dan Williams wrote:
> On Mon, Apr 17, 2017 at 7:14 AM, Dan Williams <dan.j.williams@intel.com> wrote:
> > On Mon, Apr 17, 2017 at 12:14 AM, Xiong Zhou <xzhou@redhat.com> wrote:
> >> Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
> >> do mmap DIO from DAX to non-DAX.
> >>
> >> This test is split from generic/413. Since DIO from DAX
> >> to non-DAX is only supported/doable when device underneath
> >> has memory(struct page) backend.
> >>
> >> By ndctl looking at SCRATCH_DEV, skip this test if it is
> >> not in "memory mode".
> >>
> >> Adding helper to check pmem device status, which requires new
> >> PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
> >> JSON format outputs.
> >>
> >> Signed-off-by: Xiong Zhou <xzhou@redhat.com>
> >> ---
> >>  common/rc             |  45 ++++++++++++++++++++
> >>  tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >>  tests/generic/423.out |   2 +
> >>  tests/generic/group   |   1 +
> >>  4 files changed, 161 insertions(+)
> >>  create mode 100755 tests/generic/423
> >>  create mode 100644 tests/generic/423.out
> >>
> >> diff --git a/common/rc b/common/rc
> >> index 78a2101..73ac79c 100644
> >> --- a/common/rc
> >> +++ b/common/rc
> >> @@ -3151,6 +3151,51 @@ _require_chattr()
> >>         rm -f $TEST_DIR/syscalltest.out
> >>  }
> >>
> >> +# Require test/scratch device nvdimm and having specific
> >> +# arttibute key/value we need.
> >> +#
> >> +# This is designed to get attr values of nvdimm persistent
> >> +# memory device, by searching sysfs.
> >> +#
> >> +# Other non-nvdimm or non-persistent-memory devices would
> >> +# fail this helper anyway.
> >> +#
> >> +# So, ONLY use this helper when you REALLY need nvdimm and
> >> +# specific attr on it.
> >> +#
> >> +_require_pmem_key_value()
> >> +{
> >> +       local dev=${1#/dev/}
> >> +       local key=$2
> >> +       local value=$3
> >> +       local region index keyfile dev_value
> >> +
> >> +       # find a filename string contains the region of dev, eg:
> >> +       #  /sys/devices/platform/e820_pmem/ndbus0/region1/\
> >> +       #  namespace1.0/block/pmem1
> >> +       #
> >> +       region=$(find /sys/ | grep $dev | grep region | head -1)
> >> +       [ -z "$region" ] && \
> >> +         _notrun "requires persistent memory $dev $key $value"
> >
> > Running 'find' in sysfs is overkill. You can go directly to the sysfs
> > path for a given block device by stat(1) on the block device special
> > file to get the device major and minor numbers. Then go directly to
> > the sysfs path for that device by following this link
> > /sys/dev/block/$major:$minor.
> 
> Of course, this is all handled for you if you just use ndctl, so I'm
> not sure what the motivation is to bypass those tools? They are widely
> available.

Yea, I think I may have lead Xiong in the wrong direction.  :-/  I thought
that we didn't need to worry about the case where we had both NFIT generated
PMEM devices and memmap generated PMEM devices, and if that was true we could
basically have a shortcut in the memmap case and not add the extra
dependencies of ndctl and jq.

In thinking about it a bit more, though, I think Dan's right about that
basically being a premature optimization.  We probably do need to consider
that case, and future-proof ourselves against other non-NFIT PMEM regions on
other architectures.  The sysfs interface isn't meant to be stable, though,
and ndctl is stable, so I think we're better off going back to using ndctl +
jq.  Sorry for the thrash.

I think your v3 changes in common/rc do exactly what you need, and you just
need to pull out the lines that special case the memmap case and you're done.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Williams April 17, 2017, 11:47 p.m. UTC | #4
On Mon, Apr 17, 2017 at 4:39 PM, Ross Zwisler
<ross.zwisler@linux.intel.com> wrote:
> On Mon, Apr 17, 2017 at 03:54:30PM -0700, Dan Williams wrote:
>> On Mon, Apr 17, 2017 at 7:14 AM, Dan Williams <dan.j.williams@intel.com> wrote:
>> > On Mon, Apr 17, 2017 at 12:14 AM, Xiong Zhou <xzhou@redhat.com> wrote:
>> >> Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
>> >> do mmap DIO from DAX to non-DAX.
>> >>
>> >> This test is split from generic/413. Since DIO from DAX
>> >> to non-DAX is only supported/doable when device underneath
>> >> has memory(struct page) backend.
>> >>
>> >> By ndctl looking at SCRATCH_DEV, skip this test if it is
>> >> not in "memory mode".
>> >>
>> >> Adding helper to check pmem device status, which requires new
>> >> PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
>> >> JSON format outputs.
>> >>
>> >> Signed-off-by: Xiong Zhou <xzhou@redhat.com>
>> >> ---
>> >>  common/rc             |  45 ++++++++++++++++++++
>> >>  tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
>> >>  tests/generic/423.out |   2 +
>> >>  tests/generic/group   |   1 +
>> >>  4 files changed, 161 insertions(+)
>> >>  create mode 100755 tests/generic/423
>> >>  create mode 100644 tests/generic/423.out
>> >>
>> >> diff --git a/common/rc b/common/rc
>> >> index 78a2101..73ac79c 100644
>> >> --- a/common/rc
>> >> +++ b/common/rc
>> >> @@ -3151,6 +3151,51 @@ _require_chattr()
>> >>         rm -f $TEST_DIR/syscalltest.out
>> >>  }
>> >>
>> >> +# Require test/scratch device nvdimm and having specific
>> >> +# arttibute key/value we need.
>> >> +#
>> >> +# This is designed to get attr values of nvdimm persistent
>> >> +# memory device, by searching sysfs.
>> >> +#
>> >> +# Other non-nvdimm or non-persistent-memory devices would
>> >> +# fail this helper anyway.
>> >> +#
>> >> +# So, ONLY use this helper when you REALLY need nvdimm and
>> >> +# specific attr on it.
>> >> +#
>> >> +_require_pmem_key_value()
>> >> +{
>> >> +       local dev=${1#/dev/}
>> >> +       local key=$2
>> >> +       local value=$3
>> >> +       local region index keyfile dev_value
>> >> +
>> >> +       # find a filename string contains the region of dev, eg:
>> >> +       #  /sys/devices/platform/e820_pmem/ndbus0/region1/\
>> >> +       #  namespace1.0/block/pmem1
>> >> +       #
>> >> +       region=$(find /sys/ | grep $dev | grep region | head -1)
>> >> +       [ -z "$region" ] && \
>> >> +         _notrun "requires persistent memory $dev $key $value"
>> >
>> > Running 'find' in sysfs is overkill. You can go directly to the sysfs
>> > path for a given block device by stat(1) on the block device special
>> > file to get the device major and minor numbers. Then go directly to
>> > the sysfs path for that device by following this link
>> > /sys/dev/block/$major:$minor.
>>
>> Of course, this is all handled for you if you just use ndctl, so I'm
>> not sure what the motivation is to bypass those tools? They are widely
>> available.
>
> Yea, I think I may have lead Xiong in the wrong direction.  :-/  I thought
> that we didn't need to worry about the case where we had both NFIT generated
> PMEM devices and memmap generated PMEM devices, and if that was true we could
> basically have a shortcut in the memmap case and not add the extra
> dependencies of ndctl and jq.
>
> In thinking about it a bit more, though, I think Dan's right about that
> basically being a premature optimization.  We probably do need to consider
> that case, and future-proof ourselves against other non-NFIT PMEM regions on
> other architectures.  The sysfs interface isn't meant to be stable, though,
> and ndctl is stable, so I think we're better off going back to using ndctl +
> jq.  Sorry for the thrash.

One additional clarification, the sysfs interface is stable from an
ABI perspective.  What is fluid is the arrival of certain attributes
relative to others due to asynchronous probing. The ndctl tool handles
this asynchronous behavior.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig April 18, 2017, 10:12 a.m. UTC | #5
On Mon, Apr 17, 2017 at 03:14:13PM +0800, Xiong Zhou wrote:
> Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
> do mmap DIO from DAX to non-DAX.
> 
> This test is split from generic/413. Since DIO from DAX
> to non-DAX is only supported/doable when device underneath
> has memory(struct page) backend.
> 
> By ndctl looking at SCRATCH_DEV, skip this test if it is
> not in "memory mode".

DAX devices don't need to be something using NFIT, so I don't think this
method is correct.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Murphy Zhou April 18, 2017, 2:49 p.m. UTC | #6
On Tue, Apr 18, 2017 at 03:12:26AM -0700, Christoph Hellwig wrote:
> On Mon, Apr 17, 2017 at 03:14:13PM +0800, Xiong Zhou wrote:
> > Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
> > do mmap DIO from DAX to non-DAX.
> > 
> > This test is split from generic/413. Since DIO from DAX
> > to non-DAX is only supported/doable when device underneath
> > has memory(struct page) backend.
> > 
> > By ndctl looking at SCRATCH_DEV, skip this test if it is
> > not in "memory mode".
> 
> DAX devices don't need to be something using NFIT, so I don't think this
> method is correct.

Ya. This commit message needs update. I'm trying another method, not being
that nvdimm specific.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ross Zwisler April 18, 2017, 4:32 p.m. UTC | #7
On Mon, Apr 17, 2017 at 03:14:13PM +0800, Xiong Zhou wrote:
> Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
> do mmap DIO from DAX to non-DAX.
> 
> This test is split from generic/413. Since DIO from DAX
> to non-DAX is only supported/doable when device underneath
> has memory(struct page) backend.
> 
> By ndctl looking at SCRATCH_DEV, skip this test if it is
> not in "memory mode".
> 
> Adding helper to check pmem device status, which requires new
> PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
> JSON format outputs.
> 
> Signed-off-by: Xiong Zhou <xzhou@redhat.com>
> ---
>  common/rc             |  45 ++++++++++++++++++++
>  tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++

generic/423 looks good to me, just need to change the memory mode detection.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Murphy Zhou April 19, 2017, 8:40 a.m. UTC | #8
On Mon, Apr 17, 2017 at 07:14:32AM -0700, Dan Williams wrote:
> On Mon, Apr 17, 2017 at 12:14 AM, Xiong Zhou <xzhou@redhat.com> wrote:
> > Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
> > do mmap DIO from DAX to non-DAX.
> >
> > This test is split from generic/413. Since DIO from DAX
> > to non-DAX is only supported/doable when device underneath
> > has memory(struct page) backend.
> >
> > By ndctl looking at SCRATCH_DEV, skip this test if it is
> > not in "memory mode".
> >
> > Adding helper to check pmem device status, which requires new
> > PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
> > JSON format outputs.
> >
> > Signed-off-by: Xiong Zhou <xzhou@redhat.com>
> > ---
> >  common/rc             |  45 ++++++++++++++++++++
> >  tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  tests/generic/423.out |   2 +
> >  tests/generic/group   |   1 +
> >  4 files changed, 161 insertions(+)
> >  create mode 100755 tests/generic/423
> >  create mode 100644 tests/generic/423.out
> >
> > diff --git a/common/rc b/common/rc
> > index 78a2101..73ac79c 100644
> > --- a/common/rc
> > +++ b/common/rc
> > @@ -3151,6 +3151,51 @@ _require_chattr()
> >         rm -f $TEST_DIR/syscalltest.out
> >  }
> >
> > +# Require test/scratch device nvdimm and having specific
> > +# arttibute key/value we need.
> > +#
> > +# This is designed to get attr values of nvdimm persistent
> > +# memory device, by searching sysfs.
> > +#
> > +# Other non-nvdimm or non-persistent-memory devices would
> > +# fail this helper anyway.
> > +#
> > +# So, ONLY use this helper when you REALLY need nvdimm and
> > +# specific attr on it.
> > +#
> > +_require_pmem_key_value()
> > +{
> > +       local dev=${1#/dev/}
> > +       local key=$2
> > +       local value=$3
> > +       local region index keyfile dev_value
> > +
> > +       # find a filename string contains the region of dev, eg:
> > +       #  /sys/devices/platform/e820_pmem/ndbus0/region1/\
> > +       #  namespace1.0/block/pmem1
> > +       #
> > +       region=$(find /sys/ | grep $dev | grep region | head -1)
> > +       [ -z "$region" ] && \
> > +         _notrun "requires persistent memory $dev $key $value"
> 
> Running 'find' in sysfs is overkill. You can go directly to the sysfs
> path for a given block device by stat(1) on the block device special
> file to get the device major and minor numbers. Then go directly to
> the sysfs path for that device by following this link

> /sys/dev/block/$major:$minor.

This sounds better. While I have trouble with getting the right region
mode through this sysfs path.

sh-4.2# ndctl list -r 2 -N
{
  "dev":"namespace2.0",
  "mode":"raw",
  "size":8589934592,
  "blockdev":"pmem2"
}
sh-4.2# cat /sys/devices/LNXSYSTM:00/device:00/ACPI0012:00/ndbus0/region2/namespace2.0/mode
raw
sh-4.2# stat -c %t:%T /dev/pmem2
103:2
sh-4.2# cat /sys/dev/block/259\:2/device/mode
raw
sh-4.2# ndctl create-namespace -f -e namespace2.0 -m memory
{
  "dev":"namespace2.0",
  "mode":"memory",
  "size":8453619712,
  "uuid":"66d5afc1-6876-4e8b-a0ba-0082af84bf82",
  "blockdev":"pmem2"
}
sh-4.2# stat -c %t:%T /dev/pmem2
103:2
sh-4.2# cat /sys/dev/block/259\:2/device/mode     # Here
pmem
sh-4.2# cat /sys/devices/LNXSYSTM:00/device:00/ACPI0012:00/ndbus0/region2/namespace2.0/mode
memory
sh-4.2# ndctl list -r 2 -N
{
  "dev":"namespace2.0",
  "mode":"memory",
  "size":8453619712,
  "uuid":"66d5afc1-6876-4e8b-a0ba-0082af84bf82",
  "blockdev":"pmem2"
}
sh-4.2# 
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Williams April 19, 2017, 3:53 p.m. UTC | #9
On Wed, Apr 19, 2017 at 1:40 AM, Xiong Zhou <xzhou@redhat.com> wrote:
> On Mon, Apr 17, 2017 at 07:14:32AM -0700, Dan Williams wrote:
>> On Mon, Apr 17, 2017 at 12:14 AM, Xiong Zhou <xzhou@redhat.com> wrote:
>> > Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
>> > do mmap DIO from DAX to non-DAX.
>> >
>> > This test is split from generic/413. Since DIO from DAX
>> > to non-DAX is only supported/doable when device underneath
>> > has memory(struct page) backend.
>> >
>> > By ndctl looking at SCRATCH_DEV, skip this test if it is
>> > not in "memory mode".
>> >
>> > Adding helper to check pmem device status, which requires new
>> > PROGs ndctl to tweaking pmem devices and jq to parse ndctl's
>> > JSON format outputs.
>> >
>> > Signed-off-by: Xiong Zhou <xzhou@redhat.com>
>> > ---
>> >  common/rc             |  45 ++++++++++++++++++++
>> >  tests/generic/423     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
>> >  tests/generic/423.out |   2 +
>> >  tests/generic/group   |   1 +
>> >  4 files changed, 161 insertions(+)
>> >  create mode 100755 tests/generic/423
>> >  create mode 100644 tests/generic/423.out
>> >
>> > diff --git a/common/rc b/common/rc
>> > index 78a2101..73ac79c 100644
>> > --- a/common/rc
>> > +++ b/common/rc
>> > @@ -3151,6 +3151,51 @@ _require_chattr()
>> >         rm -f $TEST_DIR/syscalltest.out
>> >  }
>> >
>> > +# Require test/scratch device nvdimm and having specific
>> > +# arttibute key/value we need.
>> > +#
>> > +# This is designed to get attr values of nvdimm persistent
>> > +# memory device, by searching sysfs.
>> > +#
>> > +# Other non-nvdimm or non-persistent-memory devices would
>> > +# fail this helper anyway.
>> > +#
>> > +# So, ONLY use this helper when you REALLY need nvdimm and
>> > +# specific attr on it.
>> > +#
>> > +_require_pmem_key_value()
>> > +{
>> > +       local dev=${1#/dev/}
>> > +       local key=$2
>> > +       local value=$3
>> > +       local region index keyfile dev_value
>> > +
>> > +       # find a filename string contains the region of dev, eg:
>> > +       #  /sys/devices/platform/e820_pmem/ndbus0/region1/\
>> > +       #  namespace1.0/block/pmem1
>> > +       #
>> > +       region=$(find /sys/ | grep $dev | grep region | head -1)
>> > +       [ -z "$region" ] && \
>> > +         _notrun "requires persistent memory $dev $key $value"
>>
>> Running 'find' in sysfs is overkill. You can go directly to the sysfs
>> path for a given block device by stat(1) on the block device special
>> file to get the device major and minor numbers. Then go directly to
>> the sysfs path for that device by following this link
>
>> /sys/dev/block/$major:$minor.
>
> This sounds better. While I have trouble with getting the right region
> mode through this sysfs path.
>
> sh-4.2# ndctl list -r 2 -N
> {
>   "dev":"namespace2.0",
>   "mode":"raw",
>   "size":8589934592,
>   "blockdev":"pmem2"
> }
> sh-4.2# cat /sys/devices/LNXSYSTM:00/device:00/ACPI0012:00/ndbus0/region2/namespace2.0/mode
> raw
> sh-4.2# stat -c %t:%T /dev/pmem2
> 103:2
> sh-4.2# cat /sys/dev/block/259\:2/device/mode
> raw
> sh-4.2# ndctl create-namespace -f -e namespace2.0 -m memory
> {
>   "dev":"namespace2.0",
>   "mode":"memory",
>   "size":8453619712,
>   "uuid":"66d5afc1-6876-4e8b-a0ba-0082af84bf82",
>   "blockdev":"pmem2"
> }
> sh-4.2# stat -c %t:%T /dev/pmem2
> 103:2
> sh-4.2# cat /sys/dev/block/259\:2/device/mode     # Here
> pmem

This is another reason to use ndctl and not sysfs directly. After the
create-namespace command the namespace is "claimed" by a pfn-device
instance which writes metadata to the device to indicate where the
struct page memmap is located. In this case the sysfs path for the
parent device is a pfn-device. So the "device/mode" link is pointing
to:

    /sys/devices/LNXSYSTM:00/device:00/ACPI0012:00/ndbus0/region2/pfn2.0/mode

...and in that case "pmem" means that the struct page memmap is being
allocated on the pmem range directly.
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jeff Moyer July 28, 2017, 2:55 p.m. UTC | #10
Christoph Hellwig <hch@infradead.org> writes:

> On Mon, Apr 17, 2017 at 03:14:13PM +0800, Xiong Zhou wrote:
>> Mount TEST_DEV as non-DAX, SCRATCH_DEV as DAX, then
>> do mmap DIO from DAX to non-DAX.
>> 
>> This test is split from generic/413. Since DIO from DAX
>> to non-DAX is only supported/doable when device underneath
>> has memory(struct page) backend.
>> 
>> By ndctl looking at SCRATCH_DEV, skip this test if it is
>> not in "memory mode".
>
> DAX devices don't need to be something using NFIT, so I don't think this
> method is correct.

Memory mode does not depend on an NFIT.  There's a superblock stored in
the persistent memory that tracks its mode when labels are not present.

-Jeff
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/common/rc b/common/rc
index 78a2101..73ac79c 100644
--- a/common/rc
+++ b/common/rc
@@ -3151,6 +3151,51 @@  _require_chattr()
 	rm -f $TEST_DIR/syscalltest.out
 }
 
+# Require test/scratch device nvdimm and having specific
+# arttibute key/value we need.
+#
+# This is designed to get attr values of nvdimm persistent
+# memory device, by searching sysfs.
+#
+# Other non-nvdimm or non-persistent-memory devices would
+# fail this helper anyway.
+#
+# So, ONLY use this helper when you REALLY need nvdimm and
+# specific attr on it.
+#
+_require_pmem_key_value()
+{
+	local dev=${1#/dev/}
+	local key=$2
+	local value=$3
+	local region index keyfile dev_value
+
+	# find a filename string contains the region of dev, eg:
+	#  /sys/devices/platform/e820_pmem/ndbus0/region1/\
+	#  namespace1.0/block/pmem1
+	#
+	region=$(find /sys/ | grep $dev | grep region | head -1)
+	[ -z "$region" ] && \
+	  _notrun "requires persistent memory $dev $key $value"
+
+	# get region number index
+	index=$(expr $region : .*region)
+
+	# find the file for the key, eg:
+	#  /sys/devices/platform/e820_pmem/ndbus0/region1/\
+	#  namespace1.0/mode
+	#
+	keyfile=$(find /sys/ | grep region${region:$index:2} \
+	  | grep namespace | grep $key)
+	[ -z "$keyfile" ] && \
+	  _notrun "requires persistent memory $dev $key $value"
+
+	# get the value and test
+	dev_value=$(cat $keyfile)
+	[ "$dev_value" != "$value" ] && \
+	  _notrun "requires $dev $key $value"
+}
+
 _get_total_inode()
 {
 	if [ -z "$1" ]; then
diff --git a/tests/generic/423 b/tests/generic/423
new file mode 100755
index 0000000..73c0b53
--- /dev/null
+++ b/tests/generic/423
@@ -0,0 +1,113 @@ 
+#! /bin/bash
+# FS QA Test 423
+#
+# mmap direct/buffered io from DAX to non-DAX mountpoints.
+# Split from generic/413, only do the DAX to non-DAX part.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_scratch_dax
+_require_test_program "feature"
+_require_test_program "t_mmap_dio"
+_require_xfs_io_command "falloc"
+_require_pmem_key_value $SCRATCH_DEV "mode" "memory"
+
+prep_files()
+{
+	rm -f $SCRATCH_MNT/tf_{s,d}
+	rm -f $TEST_DIR/tf_{s,d}
+
+	$XFS_IO_PROG -f -c "falloc 0 $tsize" \
+		$SCRATCH_MNT/tf_{s,d} >> $seqres.full 2>&1
+	$XFS_IO_PROG -f -c "falloc 0 $tsize" \
+		$TEST_DIR/tf_{s,d} >> $seqres.full 2>&1
+}
+
+t_dax_to_nondax()
+{
+	prep_files
+	src/t_mmap_dio $SCRATCH_MNT/tf_s \
+		$TEST_DIR/tf_d $1 "dio dax to nondax"
+
+	prep_files
+	src/t_mmap_dio -b $SCRATCH_MNT/tf_s \
+		$TEST_DIR/tf_d $1 "buffered dax to nondax"
+}
+
+do_tests()
+{
+	# less than page size
+	t_dax_to_nondax 1024
+	# page size
+	t_dax_to_nondax `src/feature -s`
+	# bigger sizes, for PMD faults
+	t_dax_to_nondax $((16 * 1024 * 1024))
+	t_dax_to_nondax $((64 * 1024 * 1024))
+}
+
+# make fs 2Mb aligned for PMD fault testing
+mkfs_opts=""
+if [ "$FSTYP" == "ext4" ]; then
+	mkfs_opts="-E stride=512,stripe_width=1"
+elif [ "$FSTYP" == "xfs" ]; then
+	mkfs_opts="-d su=2m,sw=1"
+fi
+_scratch_mkfs "$mkfs_opts" > /dev/null 2>&1
+
+# mount SCRATCH_DEV with dax option, TEST_DEV not
+export MOUNT_OPTIONS=""
+export TEST_FS_MOUNT_OPTS=""
+_test_cycle_mount
+_fs_options $TEST_DEV | grep -qw "dax" && \
+	_notrun "we need $TEST_DEV mount without dax"
+_scratch_mount "-o dax"
+
+tsize=$((128 * 1024 * 1024))
+
+do_tests
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/generic/423.out b/tests/generic/423.out
new file mode 100644
index 0000000..22c4029
--- /dev/null
+++ b/tests/generic/423.out
@@ -0,0 +1,2 @@ 
+QA output created by 423
+Silence is golden
diff --git a/tests/generic/group b/tests/generic/group
index d747385..52553fa 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -425,3 +425,4 @@ 
 420 auto quick punch
 421 auto quick encrypt dangerous
 422 auto quick
+423 auto quick