Skip to contentSkip to conversation

zuf: ZUFS Zero-copy User-mode FileSystem

PATCH In review Boaz Harrosh 7 participants 30 messages Sep 26, 2019 – Nov 14, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover zuf: ZUFS Zero-copy User-mode FileSystem

I would please like to submit the Kernel code part of the ZUFS file system, for review. V02

[v02]
The git of the changes over v01 can be found at: (Note based on v5.2)
git https://github.com/NetApp/zufs-zuf upstream-5.2-v02-fixes

The patches submitted are at:
git https://github.com/NetApp/zufs-zuf upstream-v02

list of changes since v01
* Based on Linux v5.3. Previous was based on v5.2 and experienced build breakage with v5.3-rcX
* Address *all* comments by the Intel Robot. The code should be completely free of any warnings.
* Some bugs found since the time of the first submission.
* More I(s) doted and T(s) crossed. Please see above upstream-5.2-v02-fixes for all the patches on top of v01 before they were re-squashed into this set.

[v01]
find v01 submission here:
https://lore.kernel.org/linux-fsdevel/[email protected]/
On github:
git https://github.com/NetApp/zufs-zuf upstream-v01

---
ZUFS is a full implementation of a VFS filesystem. But mainly it is a very new way to communicate with user-mode servers.
With performance and scalability never seen before. (<4us latency) Why? the core communication with user-mode is completely lockless, per-cpu locality, NUMA aware.

The Kernel code presented here can be found at:
https://github.com/NetApp/zufs-zuf upstream

And the User-mode Server + example FSs here:
https://github.com/NetApp/zufs-zus upstream

ZUFS - stands for Zero-copy User-mode FS
The Intention of this project is performance and low-latency.
* True zero copy end to end of both data and meta data.
* Very *low latency*, very high CPU locality, lock-less parallelism.
* Synchronous operations (for low latency)
* Numa awareness

Short description:
ZUFS is a from scratch implementation of a filesystem-in-user-space, which tries to address the above goals. from the get go it is aimed for pmem based FSs. But supports any other type of FSs.
The novelty of this project is that the interface is designed with a modern multi-core NUMA machine in mind down to the ABI.
Also it utilizes the normal mount API of the Kernel.
Multiple block devices are supported per superblock, Kernel owns those devices. FileSystem types are registered/exposed via the regular way

The Kernel is released as a pure GPLv2 License. The user-mode core is BSD-3 so to be friendly with other OSs.

Current status: There are a couple of trivial open-source filesystem implementations and a full blown proprietary implementation from Netapp.
3 more ports to more serious open-source filesystems are on the way.
A usermode CEPH client, a ZFS implementation, and port of the infamous PMFS to demonstrate the amazing pmem performance under zufs.
(Will be released as Open source when they are ready)

Together with the Kernel module submitted here the User-mode-Server and the zusFSs User-mode plugins, pass Netapp QA including xfstests + internal QA tests. And is released to costumers as Maxdata.
So it is very stable and performant

In the git repository above there is also a backport for rhel 7.6 7.7 and 8.0 Including rpm packages for Kernel and Server components.
(Also available evaluation licenses of Maxdata 1.5 for developers.
Please contact Amit Golander <[email protected]> if you need one)

Performance:
A simple fio direct 4k random write test with incrementing number of threads.

[fuse]
threads wr_iops wr_bw wr_lat
1 33606 134424 26.53226
2 57056 228224 30.38476
4 88667 354668 40.12783
7 116561 466245 53.98572
8 129134 516539 55.6134

[fuse-splice]
threads wr_iops wr_bw wr_lat
1 39670 158682 21.8399
2 51100 204400 34.63294
4 75220 300882 47.42344
7 97706 390825 63.04435
8 98034 392137 73.24263

[xfs-dax]
threads wr_iops wr_bw wr_lat

[Maxdata-1.5-zufs]
threads wr_iops wr_bw wr_lat
1 1041802 260,450 3.623
2 1983997 495,999 3.808
4 3829456 957,364 3.959
7 4501154 1,125,288 5.895330
8 4400698 1,100,174 6.922174

I have used an 8 way KVM-qemu with 2 NUMA nodes.
(on an Intel(R) Xeon(R) CPU E3-1230 v6 @ 3.50GHz)

Running fio with 4k random writes O_DIRECT | O_SYNC to a DRAM simulated pmem. (memmap=! at grub)
Fuse-fs was a memcpy same 4k null-FS
fio was run with more and more threads (see threads column) to test for scalability.

We see a bit of a slowdown when pushing to 8 threads. This is mainly a scheduler and KVM issue. Big metal machines do better (more flat scalability) but also degrade a bit on full load I will try to post real metal scores later.

The in Kernel xfs-dax is slower than a zufs-pmem because:
1. It was not built specifically for pmem so there are latency issues (async operations) and extra copies in places.
2. In writes because of the Journal there are actually 3 IOPs for every write. Where with pmem other means can keep things crash-proof.
3. Because in random write + DAX each block is written twice It is first ZEROed then copied too.
4. But mainly because we use a single pmem on one of the NUMAs with zufs we put a pmem device on each NUMA node. And each core writes locally. So the memory bandwith is doubled. (Perhaps there is a way to use a dm configuration that makes this better but at the base xfs is not NUMA aware)
Is why I chose writes. With reads xfs-dax is much faster. In zufs reads are actually 10% slower because in reads we do regular memcpy-from-pmem which is exactly 10% slower than mov_nt operations

[Changes since last RFC submission]

Lots and lots of changes since then. More hardening stability and more fixtures.

But mainly is the NEW-IO way.
The old way of IO where we mmap application-pages into the Server is still there because there are modes where this is faster still. For example direct IO from network type of FSs. We are all about choice. (The zusFS is the one that decides which mode to use)
But the results above are with the NEW-IO way. The new way is - we ask the Server what are the blocks to read/write (both pmem or bdev) and the IO or pmem_memcpy is done in Kernel.
(We do not yet cache these results in Kernel but might in future
((when caching will actually make things faster currently xarray does
not scale for us)))

[TODOs]
1. EZUFS_ASYNC is not submitted here. It is implemented but there are no current users so it was never fully tested (waiting for a user)
2. Support Page-cache. This one is very easy to do, but again no users yet
3. more stuff ....

Please help with *reviews*, comments, questions. We believe this is a very important project that opens new ways for implementing Server-applications, including but not restricted to FS Server applications.

Thank you
Boaz

----------------------------------------------------------------
Boaz Harrosh (16):
fs: Add the ZUF filesystem to the build + License
MAINTAINERS: Add the ZUFS maintainership
zuf: Preliminary Documentation
zuf: zuf-rootfs
zuf: zuf-core The ZTs
zuf: Multy Devices
zuf: mounting
zuf: Namei and directory operations
zuf: readdir operation
zuf: symlink
zuf: Write/Read implementation
zuf: mmap & sync
zuf: More file operation
zuf: ioctl implementation
zuf: xattr && acl implementation
zuf: Support for dynamic-debug of zusFSs

 Documentation/filesystems/zufs.txt |  386 +++++++++++++++++++++++++++++++
 MAINTAINERS                        |    6 +
 fs/Kconfig                         |    1 +
 fs/Makefile                        |    1 +
 fs/zuf/Kconfig                     |   24 ++
 fs/zuf/Makefile                    |   23 ++
 fs/zuf/_extern.h                   |  179 +++++++++++++++
 fs/zuf/_pr.h                       |   68 ++++++
 fs/zuf/acl.c                       |  270 ++++++++++++++++++++++
 fs/zuf/directory.c                 |  171 ++++++++++++++
 fs/zuf/file.c                      |  825 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/inode.c                     |  630 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/ioctl.c                     |  309 +++++++++++++++++++++++++
 fs/zuf/md.c                        |  742 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/md.h                        |  332 +++++++++++++++++++++++++++
 fs/zuf/md_def.h                    |  141 ++++++++++++
 fs/zuf/mmap.c                      |  300 ++++++++++++++++++++++++
 fs/zuf/module.c                    |   28 +++
 fs/zuf/namei.c                     |  435 +++++++++++++++++++++++++++++++++++
 fs/zuf/relay.h                     |  104 +++++++++
 fs/zuf/rw.c                        | 1051 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/super.c                     |  954 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/symlink.c                   |   74 ++++++
 fs/zuf/t1.c                        |  145 ++++++++++++
 fs/zuf/t2.c                        |  356 ++++++++++++++++++++++++++++
 fs/zuf/t2.h                        |   68 ++++++
 fs/zuf/xattr.c                     |  314 +++++++++++++++++++++++++
 fs/zuf/zuf-core.c                  | 1735 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf-root.c                  |  519 +++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf.h                       |  452 ++++++++++++++++++++++++++++++++++++
 fs/zuf/zus_api.h                   | 1075 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 31 files changed, 11718 insertions(+)
 create mode 100644 Documentation/filesystems/zufs.txt
 create mode 100644 fs/zuf/Kconfig
 create mode 100644 fs/zuf/Makefile
 create mode 100644 fs/zuf/_extern.h
 create mode 100644 fs/zuf/_pr.h
 create mode 100644 fs/zuf/acl.c
 create mode 100644 fs/zuf/directory.c
 create mode 100644 fs/zuf/file.c
 create mode 100644 fs/zuf/inode.c
 create mode 100644 fs/zuf/ioctl.c
 create mode 100644 fs/zuf/md.c
 create mode 100644 fs/zuf/md.h
 create mode 100644 fs/zuf/md_def.h
 create mode 100644 fs/zuf/mmap.c
 create mode 100644 fs/zuf/module.c
 create mode 100644 fs/zuf/namei.c
 create mode 100644 fs/zuf/relay.h
 create mode 100644 fs/zuf/rw.c
 create mode 100644 fs/zuf/super.c
 create mode 100644 fs/zuf/symlink.c
 create mode 100644 fs/zuf/t1.c
 create mode 100644 fs/zuf/t2.c
 create mode 100644 fs/zuf/t2.h
 create mode 100644 fs/zuf/xattr.c
 create mode 100644 fs/zuf/zuf-core.c
 create mode 100644 fs/zuf/zuf-root.c
 create mode 100644 fs/zuf/zuf.h
 create mode 100644 fs/zuf/zus_api.h
#1 lore raw

PATCH v2 1/16 fs: Add the ZUF filesystem to the build + License

This adds the ZUF filesystem-in-user_mode module to the fs/ build system.

Also added:
* fs/zuf/Kconfig
* fs/zuf/module.c - This file contains the LICENCE of zuf code base
* fs/zuf/Makefile - Rather empty Makefile with only module.c above

I add the fs/zuf/Makefile to demonstrate that at every patch-set stage code still compiles and there are no external references outside of the code already submitted.

Off course only at the very last patch we have a working ZUF feeder

[LICENCE]

zuf.ko is a GPLv2 licensed project.

However the ZUS user mode Server is a BSD-3-Clause licensed project.
Therefor you will see that:

	zus_api.h
	md_def.h
	md.h
	t2.h

Are common files with the ZUS project. And are separately dual Licensed as:
GPL-2.0 WITH Linux-syscall-note or BSD-3-Clause.

Any code contributor to these headers should note that her/his code to these files only, is dual licensed.

This is for the obvious reasons as these headers define the API between Kernel and the user-mode Server.

---
 fs/Kconfig       |  1 +
 fs/Makefile      |  1 +
 fs/zuf/Kconfig   | 24 ++++++++++++
 fs/zuf/Makefile  | 14 +++++++
 fs/zuf/module.c  | 28 ++++++++++++++
 fs/zuf/zus_api.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 164 insertions(+)
 create mode 100644 fs/zuf/Kconfig
 create mode 100644 fs/zuf/Makefile
 create mode 100644 fs/zuf/module.c
 create mode 100644 fs/zuf/zus_api.h
fs/Kconfig +1 -0
index bfb1c6095c7a..452244733bb5 100644
@@ -261,6 +261,7 @@ source "fs/romfs/Kconfig"
 source "fs/pstore/Kconfig"
 source "fs/sysv/Kconfig"
 source "fs/ufs/Kconfig"
+source "fs/zuf/Kconfig"
 
 endif # MISC_FILESYSTEMS
 
fs/Makefile +1 -0
index d60089fd689b..178e27ddd605 100644
@@ -130,3 +130,4 @@ obj-$(CONFIG_F2FS_FS)		+= f2fs/
 obj-$(CONFIG_CEPH_FS)		+= ceph/
 obj-$(CONFIG_PSTORE)		+= pstore/
 obj-$(CONFIG_EFIVAR_FS)		+= efivarfs/
+obj-$(CONFIG_ZUFS_FS)		+= zuf/
fs/zuf/Kconfig new file +24 -0
new file mode 100644
index 000000000000..58288f4245c2
@@ -0,0 +1,24 @@
+config ZUFS_FS
+	tristate "ZUF - Zero-copy User-mode Feeder"
+	depends on BLOCK
+	depends on ZONE_DEVICE
+	select CRC16
+	select MEMCG
+	help
+	   ZUFS Kernel part.
+	   To enable say Y here.
+
+	   To compile this as a module,  choose M here: the module will be
+	   called zuf.ko
+
+config ZUF_DEBUG
+	bool "ZUF: enable debug subsystems use"
+	depends on ZUFS_FS
+	default n
+	help
+	  INTERNAL QA USE ONLY!!! DO NOT USE!!!
+	  Please leave as N here
+
+	  This option adds some extra code that helps
+	  in QA testing of the code. It may slow the
+	  operation and produce bigger code
fs/zuf/Makefile new file +14 -0
new file mode 100644
index 000000000000..452cec55f34d
@@ -0,0 +1,14 @@
+#
+# ZUF: Zero-copy User-mode Feeder
+#
+# Copyright (c) 2018 NetApp Inc. All rights reserved.
+#
+# ZUFS-License: GPL-2.0. See module.c for LICENSE details.
+#
+# Makefile for the Linux zufs Kernel Feeder.
+#
+
+obj-$(CONFIG_ZUFS_FS) += zuf.o
+
+# Main FS
+zuf-y += module.o
fs/zuf/module.c new file +28 -0
new file mode 100644
index 000000000000..523633c1bf9d
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * zuf - Zero-copy User-mode Feeder
+ *
+ * Copyright (c) 2018 NetApp Inc. All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will 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, see <https://www.gnu.org/licenses/>.
+ */
+#include <linux/module.h>
+
+#include "zus_api.h"
+
+MODULE_AUTHOR("Boaz Harrosh <[email protected]>");
+MODULE_AUTHOR("Sagi Manole <[email protected]>");
+MODULE_DESCRIPTION("Zero-copy User-mode Feeder");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(__stringify(ZUFS_MAJOR_VERSION) "."
+		__stringify(ZUFS_MINOR_VERSION));
fs/zuf/zus_api.h new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.21.0
#2 lore raw

PATCH v2 2/16 MAINTAINERS: Add the ZUFS maintainership

In reply to Boaz Harrosh

ZUFS sitting in the fs/zuf/ directory is maintained by Netapp. (I added my email)

I keep this as separate patch as this file might be a source of conflicts

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index a50e97a63bc8..8703871c1505 100644
@@ -17867,6 +17867,12 @@ L:	[email protected]
 S:	Maintained
 F:	mm/zswap.c
 
+ZUFS ZERO COPY USER-MODE FILESYSTEM
+M:	Boaz Harrosh <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	fs/zuf/
+
 THE REST
 M:	Linus Torvalds <[email protected]>
 L:	[email protected]
Signature · 1 line
2.21.0
#3 lore raw

PATCH v2 3/16 zuf: Preliminary Documentation

In reply to Boaz Harrosh

Adding Documentation/filesystems/zufs.txt.

Adding some Documentation first. So to give the reviewer of the coming patch-set. Some background and overview of the all system.

[v2]
Incorporated Randy's few comments.

Randy Please give it an harder review?

---
 Documentation/filesystems/zufs.txt | 386 +++++++++++++++++++++++++++++
 1 file changed, 386 insertions(+)
 create mode 100644 Documentation/filesystems/zufs.txt
Documentation/filesystems/zufs.txt new file +386 -0
new file mode 100644
index 000000000000..2a347a446aa7
@@ -0,0 +1,386 @@
+ZUFS - Zero-copy User-mode FileSystem
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Trees:
+	git clone https://github.com/NetApp/zufs-zuf -b upstream
+	git clone https://github.com/NetApp/zufs-zus -b upstream
+
+patches, comments, questions, requests to:
+	[email protected]
+
+Introduction:
+~~~~~~~~~~~~~
+
+ZUFS - stands for Zero-copy User-mode FS
+▪ It is geared towards true zero copy end to end of both data and meta data.
+▪ It is geared towards very *low latency*, very high CPU locality, lock-less
+  parallelism.
+▪ Synchronous operations
+▪ Numa awareness
+
+  ZUFS is a, from scratch, implementation of a filesystem-in-user-space, which
+tries to address the above goals. It is aimed for pmem based FSs. But supports
+any other type of FSs
+
+Glossary and names:
+~~~~~~~~~~~~~~~~~~~
+
+ZUF - Zero-copy User-mode Feeder
+  zuf.ko is the Kernel VFS component. Its job is to interface with the Kernel
+  VFS and dispatch commands to a User-mode application Server.
+  Uptodate code is found at:
+	git clone https://github.com/NetApp/zufs-zuf -b upstream
+
+ZUS - Zero-copy User-mode Server
+  zufs utilizes a User-mode server application. That takes care of the detailed
+  communication protocol and correctness with the Kernel.
+  In turn it utilizes many zusFS Filesystem plugins to implement the actual
+  on disc Filesystem.
+  Uptodate code is found at:
+	git clone https://github.com/NetApp/zufs-zus -b upstream
+
+zusFS - FS plugins
+  These are .so loadable modules that implement one or more Filesystem-types
+  (mount -t xyz).
+  The zus server communicates with the plugin via a set of function vectors
+  for the different operations. And establishes communication via defined
+  structures.
+
+Filesystem-type:
+  At startup zus registers with the Kernel one or more Filesystem-type(s)
+  Associated with the type is a unique type-name (mount -t foofs) +
+  different info about the fs, like a magic number and so on.
+  One Server can support many FS-types, in turn each FS-type can mount
+  multiple super-blocks, each supporting multiple devices.
+
+Device-Table (MDT) - A zufs FS can support multiple devices
+  ZUF in Kernel may receive, like any mount command a block-device or none.
+  For the former if the specified FS-types states so in a special field.
+  The mount will look for a Device table. A list of devices in a specific
+  order sitting at some offset on each block-device. The system will then
+  proceed to open and own all these devices and associate them to the mounting
+  super-block.
+  If FS-type specifies a -1 at DT_offset then there is no device table
+  and a DT of a single device is created. (If we have no devices, none
+  is specified than we operate without any block devices. (Mount options give
+  some indication of the storage information))
+  The device table has special consideration for pmem devices and will
+  present the all linear array of devices to zus, as one flat mmap space.
+  Alternatively all non-pmem devices are also provided an interface
+  with facility of data movement from pmem to slower devices.
+  A detailed NUMA info is exported to the Server for maximum utilization.
+  Each device has an associated NUMA node, so Server can optimize IO to
+  these devices
+
+pmem: (Also called t1)
+  Multiple pmem devices are presented to the server as a single
+  linear file mmap. Something like /dev/dax. But it is strictly
+  available only to the specific super-block that owns it.
+
+Shadow: (For debugging)
+  "Shadow" is used for debugging the correct persistence of pmem based
+  filesystems. With pmem if modified a user must call cl_flush/sfence
+  for the data to be guarantied resistance. This is very hard to test
+  and time consuming. So for that we invented the shadow.
+  There is a special mode bit in the MDT header that denotes a shadow
+  system. In a shadow setup each pmem device is divided in half. First
+  half is available for FS storage. The second half is a Shadow. IE
+  each time the FS calls cl_flush or mov_nt the data is then memcopied
+  to the shadow.
+  At mount time the Shadow is copied onto the main part. And thous
+  presenting only those bits that where persisted by the FS. So a simple
+  remount can simulate a full machine reboot.
+  The Shadow is presented as the upper part of the mmaped region. IE
+  the all t1 ranged is repeated again. The zus core code fasilitates
+  zusFS implementors in accessing this facility
+
+zufs_dpp_t - Dual port pointer type
+  At some points in the protocol there are objects that return from zus
+  (The Server) to the Kernel via a dpp_t. This is a special kind of pointer
+  It is actually an offset 8 bytes aligned with the 3 low bits specifying
+  a pool code: [offset = dpp_t & ~0x7] [pool = dpp_t & 0x7]
+  pool == 0 means the offset is in pmem who's management is by zuf and
+  a full easy access is provided for zus.
+
+  pool != 0 Is a pre-established file (up to 6 such files per sb) where
+  the zus has an mmap on the file and the Kernel can access that data
+  via an offset into the file.
+  pool == 7 denotes an offset into the application buffers associated
+  with the current IO.
+  All dpp_t objects life time rules are strictly defined.
+  Mainly the primary use of dpp_t is the on-pmem inode structure. Both
+  zus and zuf can access and change this structure. On any modification
+  the zus is called so to be notified of any changes, persistence.
+  More such objects are: Symlinks, xattrs, data-blocks etc...
+
+Relay-wait-object:
+  communication between Kernel and server are done via zus-threads that
+  sleep in Kernel (inside an IOCTL) and wait for commands. Once received
+  the IOCTL returns operation id executed and the return info is returned via
+  a new IOCTL call, which then waits for the next operation.
+  To wake up the sleeping thread we use a Relay-wait-object. Currently
+  it is two waitqueue_head(s) back to back.
+  In future we should investigate the use of a new special scheduler object
+  That switches from thread A to predefined thread ZT context without passing
+  through the scheduler at all.
+  (The switching is already very fast, faster then anything currently
+   in the Kernel. But I believe I can shave another 1 micro off a roundtrip)
+
+ZT-threads-array:
+  The novelty of the zufs is the ZT-threads system. 3 threads or more are
+  pre-created for each active core in the system.
+  ▪ The thread is AFFINITY set for that single core only.
+  ▪ Special communication file per ZT (O_TMPFILE + IOCTL_ZUFS_INIT)
+    At initialization the ZT thread communicates through a ZT_INIT ioctl
+    and registers as the handler of that core (Channel)
+  ▪ Also for each ZT, Kernel allocates an IOCTL-buffer that is directly
+    accessed by Kernel. In turn that IOCTL-buffer is mmaped by zus
+    for the Server access of that communication buffer. (This is for zero
+    copy operations as well as avoiding the smem memory barrier)
+  ▪ IOCTL_ZU_WAIT_OPT – threads sleeps in Kernel waiting for an operation
+    via the IOCTL_ZU_WAIT_OPT call.
+
+  ▪ On operation dispatch current CPU's ZT free channel is selected.
+    Operation info is set into the IOCTL-buffer, the ZT is woken and the
+    application thread is put to sleep.
+  ▪ After execution, ZT returns to kernel (IOCTL_ZU_WAIT_OPT), app is released,
+    Server wait for new operation on that CPU.
+  ▪ Each ZT has a cyclic logic. Each call to IOCTL_ZU_WAIT_OPT from Server
+    returns the results of the previous operation, before going to sleep
+    waiting to receive a new operation.
+	zus			zuf-zt				application
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+     ---> IOCTL_ZU_WAIT_OPT    if (app-waiting)
+     |					wake-up-application	 -> return to app
+     |				FS-WAIT
+     |				|				<- POSIX call
+     |				V		<- fs-wake-up(dispatch)
+     |			<- return with new command
+     |--<- do_new_operation
+
+ZUS-mount-thread:
+  The system utilizes a single mount thread. (This thread is not affinity to any
+  core).
+  ▪ It will first Register all FS-types supported by this Server (By calling
+    all zusFS plugins to register their supported types). Once done
+  ▪ As above, the thread sleeps in Kernel via the IOCTL_ZU_MOUNT call.
+  ▪ When the Kernel receives a mount request (vfs calles the fs_type->mount opt)
+    a mount is dispatched back to zus.
+  ▪ NOTE: That only on very first mount the above ZT-threads-array is created
+    the same ZT-array is then used for all super-blocks in the system
+  ▪ As part of the mount command in the context of this same mount-thread
+    a call to IOCTL_ZU_GRAB_PMEM will establish an interface to the pmem
+    Associated with this super_block
+  ▪ On return like above a new call to IOCTL_ZU_MOUNT will return info of the
+    mount before sleeping in kernel waiting for a new dispatch. All SB info
+    is provided to zuf, including the root inode info. Kernel then proceeds
+    to complete the mount call.
+  ▪ NOTE that since there is a single mount thread lots of FS-registration
+    super_block and pmem management are lockless.
+
+Philosophy of operations:
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+1. [zuf-root]
+
+On module load  (zuf.ko) A special pseudo FS is mounted on /sys/fs/zuf. This is
+called zuf-root.
+The zuf-root has no visible files. All communication is done via special-files.
+special-files are open(O_TMPFILE) and establish a special role via an
+IOCTL. (Example above ZT-thread is one such special file)
+All communications with the server are done via the zuf-root. Each root owns
+many FS-types and each FS-type owns many super-blocks of this type. All Sharing
+the same communication channels.
+Since all FS-type Servers live in the same zus application address space, at
+times. If the administrator wants to separate between different servers, he/she
+can mount a new zuf-root and point a new server instance on that new mount,
+registering other FS-types on that other instance. The all communication array
+will then be duplicated as well.
+(Otherwise pointing a new server instance on a busy root will return an error)
+
+2. [zus server start]
+  ▪ On load all configured zusFS plugins are loaded.
+  ▪ The Server starts by starting a single mount thread.
+  ▪ It than proceeds to register with Kernel all FS-types it will support.
+    (This is done on the single mount thread, so FS-registration and
+     mount/umount operate in a single thread and therefor need not any locks)
+  ▪ Sleeping in the Kernel on a special-file of that zuf-root. waiting for
+    a mount command.
+
+3. [mount -t xyz]
+  [In Kernel]
+  ▪ If xyz was registered above as part of the Server startup. the regular
+    mount command will come to the zuf module with a zuf_mount() call. with
+    the xyz-FS-info. In turn this points to a zuf-root.
+  ▪ Code than proceed to load a device-table of devices as  specified above.
+    It then establishes an multi_devices object with a specific sb_id.
+  ▪ It proceeds to call mount_bdev. Always with the same main-device
+    thous fully sporting automatic bind mounts. Even if different
+    devices are given to the mount command.
+  ▪ In zuf_fill_super it will then dispatch (awaken) the mount thread
+    specifying two parameters. One the FS-type to mount, and then
+    the sb_id Associated with this super_block.
+
+  [In zus]
+  ▪ A zus_super_block_info is allocated.
+  ▪ zus calls PMEM_GRAB(sb_id) to establish a direct mapping to its
+    pmem devices. On return we have full access to our PMEM
+
+  ▪ ZT-threads-array
+    If this is the first mount the ZT-threads-array is created and
+    established. The mount thread will wait until all zt-threads finished
+    initialization and ready to rock.
+  ▪ Root-zus_inode is loaded and is returned to kernel
+  ▪ More info about the mount like block sizes and so on are returned to kernel.
+
+  [In Kernel]
+   The zuf_fill_super is finalized vectors established and we have a new
+   super_block ready for operations.
+
+4. An FS operation like create or WRITE/READ and so on arrives from application
+   via VFS. Eventually an Operation is dispatched to zus:
+   ▪ A special per-operation descriptor is filled up with all parameters.
+   ▪ A current CPU channel is grabbed. the operation descriptor is put on
+     that channel (ZT). Including get_user_pages or Kernel-pages associated
+     with this OPT.
+   ▪ The ZT is awaken, app thread put to sleep.
+   ▪ Optionally in ZT context pages are mapped to that ZT-vma. This is so we
+     are sure the map is only on a single core. And no other core's TLB is
+     affected.
+   ▪ ZT thread is returned to user-space.
+   ▪ In ZT context the zus Server calls the appropriate zusFS->operation
+     vector. Output params filled.
+   ▪ zus calls again with an IOCTL_ZU_WAIT_OPT with the same descriptor
+     to return the requested info.
+   ▪ At Kernel (zuf) the app thread is awaken with the results, and the
+     ZT thread goes back to sleep waiting a new operation.
+
+   ZT rules:
+       A ZT thread should try to minimize it's sleeps. it might take locks
+   In which case we will see that the same CPU channel is reentered via another
+   application/thread. But now that CPU channel is taken.  What we do is we
+   utilize a few channels (ZTs) per core and those threads may grab another
+   channel. But this only postpones the problem. On a busy contended system,
+   all such channels will be consumed. If all channels are taken the
+   application thread is put on a busy scheduling wait until a channel can
+   be grabbed.
+   If The server needs to sleep for a long time it should utilize the
+   ZUFS_ASYNC return option. The app is then kept sleeping on an
+   operation-context object and the ZT freed for foreground operation.
+   At some point in time when the server completes the delayed operation
+   it will notify the Kernel with a special async IO-context cookie.
+   And the app will be awakened.
+
+4. On umount the operation is reversed and all resources are released.
+5. In case of an application or Server crash, all resources are Associated
+   with files, on file_release these resources are caught and freed.
+
+Objects and life-time
+~~~~~~~~~~~~~~~~~~~~~
+
+Each Kernel object type has an assosiated zus Server object type who's life
+time is governed by the life-time of the Kernel object. Therefor the Server's
+job is easy because it need not establish any object caches / hashes and so on.
+
+Inside zus all objects are allocated by the zusFS plugin. So in turn it can
+allocate a bigger space for its own private data and access it via the
+container_off() coding pattern. So when I say below a zus-object I mean both
+zus public part + zusFS private part of the same object.
+
+All operations return a User-mode pointer that are opaque to the the Kernel
+code, they are just a cookie which is returned back to zus, when needed.
+At times when we want the Kernel to have direct access to a zus object like
+zufs_inode, along with the cookie we also return a dpp_t, with a defined
+structure.
+
+Kernel object 			| zus object 		| Kernel access (via dpp_t)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+zuf_fs_type
+	file_system_type	| zus_fs_info		| no
+
+zuf_sb_info
+	super_block		| zus_sb_info		| no
+
+zuf_inode_info			|			|
+	vfs_inode		| zus_inode_info	| no
+	zufs_inode *		| 	zufs_inode *	| yes
+	synlink *		|	char-array	| yes
+	xattr**			|	zus_xattr	| yes
+
+When a Kernel object's time is to die, a final call to zus is
+dispatched so the associated object can also be freed. Which means
+that on memory pressure when object caches are evicted also the zus
+memory resources are freed.
+
+
+How to use zufs:
+~~~~~~~~~~~~~~~~
+
+The most updated documentation of how to use the latest code bases
+is the script (set of scripts) at fs/do-zu/zudo on the zus git tree
+
+We the developers at Netapp use this script to mount and test our
+latest code. So any new Secret will be found in these scripts. Please
+read them as the ultimate source of how to operate things.
+
+We assume you cloned these git trees:
+[]$ mkdir zufs; cd zufs
+[]$ git clone https://github.com/NetApp/zufs-zuf -b upstream
+[]$ git clone https://github.com/NetApp/zufs-zuf -b upstream
+
+This will create the following trees
+zufs/zus - Source code for Server
+zufs/zuf - Linux Kernel source tree to compile and install on your machine
+
+Also specifically:
+zufs/zus/fs/do-zu/zudo - script Documenting how to run things
+
+[]$ cd zufs
+
+First time
+[] zus/fs/do-zu/zudo
+this will create a file:
+	zus/fs/do-zu/zu.conf
+
+Edit this file for your environment. Devices, mount-point and so on.
+On first run an example file will be created for you. Fill in the
+blanks. Most params can stay as is in most cases
+
+Now lets start running:
+
+[1]$ zus/fs/do-zu/zudo mkfs
+This will run the proper mkfs command selected at zu.conf file
+with the proper devices.
+
+[2]$ zus/fs/do-zu/zudo zuf-insmod
+This loads the zuf.ko module
+
+[3]$ zus/fs/do-zu/zudo zuf-root
+This mounts the zuf-root FS above on /sys/fs/zuf (automatically created in [2])
+
+[4]$ zus/fs/do-zu/zudo zus-up
+This runs the zus daemon in the background
+
+[5]$ zus/fs/do-zu/zudo mount
+This mount the mkfs FS above on the specified dir in zu.conf
+
+To run all the 5 commands above at once do:
+[]$ zus/fs/do-zu/zudo up
+
+To undo all the above in reverse order do:
+[]$ zus/fs/do-zu/zudo down
+
+And the most magic command is:
+[]$ zus/fs/do-zu/zudo again
+Will do a "down", then update-mods, then "up"
+(update-mods is a special script to copy the latest compiled binaries)
+
+Now you are ready for some:
+[]$ zus/fs/do-zu/zudo xfstest
+xfstests is assumed to be installed in the regular /opt/xfstests dir
+
+Again please see inside the scripts what each command does
+these scripts are the ultimate Documentation, do not believe
+anything I'm saying here. (Because it is outdated by now)
+
+Have a nice day
Signature · 1 line
2.21.0
#4 lore raw

PATCH v2 4/16 zuf: zuf-rootfs

In reply to Boaz Harrosh

zuf-root is a pseudo FS that the zusd Server communicates through, registers new file-systems. receives new mount requests.

In this patch we have the bring up of that special FS.

The principal communication with zuf-rootfs is done through tmep-files + io-ctls.
Caller does an open(O_TMPFILE) and invokes some IOCTL_XXX on the file. The specific ioctl establishes one of zuf_special_file types object and attaches the object to the file-ptr and by that defining special behavior for that object.

Otherwise zuf-rootfs is not an FS at all. It has a few viewable variable files, exposing state and info about the system. In this patch we can see the "state" variable-file, that denotes to user-mode when the Kernel is ready for new mounts. And the registered_fs which exposes what zufFS(s) where registered with the Kernel.

There is a one-to-one relationship between a zuf-root SB and a zusd Server. Each zusd Server can support multiple zusFS plugins and register multiple filesystem-types.

The zuf-rootfs (mount -t zuf) is usually mounted on /sys/fs/zuf. The /sys/fs/zuf directory is automatically created when zuf.ko is loaded. If an admin wants to run more zusd server applications she/he can mount a second instance of -t zuf on some dir and point the new zusd Server to it. (zusd has an optional path argument). Otherwise a second instance attempting to communicate with a busy zuf-root will fail.

TODO: How to trigger a first mount on module_load. Currently admin needs to manually "mount -t zuf none /sys/fs/zuf"

---
 fs/zuf/Makefile   |   4 +
 fs/zuf/_extern.h  |  41 +++++
 fs/zuf/_pr.h      |  63 +++++++
 fs/zuf/super.c    |  53 ++++++
 fs/zuf/zuf-core.c |  69 ++++++++
 fs/zuf/zuf-root.c | 438 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf.h      | 116 ++++++++++++
 fs/zuf/zus_api.h  |  36 ++++
 8 files changed, 820 insertions(+)
 create mode 100644 fs/zuf/_extern.h
 create mode 100644 fs/zuf/_pr.h
 create mode 100644 fs/zuf/super.c
 create mode 100644 fs/zuf/zuf-core.c
 create mode 100644 fs/zuf/zuf-root.c
 create mode 100644 fs/zuf/zuf.h
fs/zuf/Makefile +4 -0
index 452cec55f34d..b08c08e73faa 100644
@@ -10,5 +10,9 @@
 
 obj-$(CONFIG_ZUFS_FS) += zuf.o
 
+# ZUF core
+zuf-y += zuf-core.o zuf-root.o
+
 # Main FS
+zuf-y += super.o
 zuf-y += module.o
fs/zuf/_extern.h new file +41 -0

41 lines not on this page · raw message

fs/zuf/_pr.h new file +63 -0

63 lines not on this page · raw message

fs/zuf/super.c new file +53 -0

53 lines not on this page · raw message

fs/zuf/zuf-core.c new file +69 -0

69 lines not on this page · raw message

fs/zuf/zuf-root.c new file +438 -0

438 lines not on this page · raw message

fs/zuf/zuf.h new file +116 -0

116 lines not on this page · raw message

fs/zuf/zus_api.h +36 -0
index 069153fc0b96..f293e03460be 100644
@@ -93,4 +93,40 @@
 
 #endif /*  ndef __KERNEL__ */
 
+struct zufs_ioc_hdr {
+	__s32 err;	/* IN/OUT must be first */
+	__u16 in_len;	/* How much to be copied *to* zus */
+	__u16 out_max;	/* Max receive buffer at dispatch caller */
+	__u16 out_start;/* Start of output parameters (to caller) */
+	__u16 out_len;	/* How much to be copied *from* zus to caller */
+			/* can be modified by zus */
+	__u16 operation;/* One of e_zufs_operation */
+	__u16 flags;	/* e_zufs_hdr_flags bit flags */
+	__u32 offset;	/* Start of user buffer in ZT mmap */
+	__u32 len;	/* Len of user buffer in ZT mmap */
+};
+
+struct register_fs_info {
+	char fsname[16];	/* Only 4 chars and a NUL please      */
+	__u32 FS_magic;         /* This is the FS's version && magic  */
+	__u32 FS_ver_major;	/* on disk, not the zuf-to-zus version*/
+	__u32 FS_ver_minor;	/* (See also struct md_dev_table)   */
+	__u32 notused;
+
+	__u64 dt_offset;
+	__u64 s_maxbytes;
+	__u32 s_time_gran;
+	__u32 def_mode;
+};
+
+/* Register FS */
+/* A cookie from user-mode given in register_fs_info */
+struct zus_fs_info;
+struct zufs_ioc_register_fs {
+	struct zufs_ioc_hdr hdr;
+	struct zus_fs_info *zus_zfi;
+	struct register_fs_info rfi;
+};
+#define ZU_IOC_REGISTER_FS	_IOWR('Z', 10, struct zufs_ioc_register_fs)
+
 #endif /* _LINUX_ZUFS_API_H */
Signature · 1 line
2.21.0
#5 lore raw

PATCH v2 5/16 zuf: zuf-core The ZTs

In reply to Boaz Harrosh

zuf-core establishes the communication channels with the ZUS User Mode Server.

In this patch we have the core communication mechanics. Which is the Novelty of this project.
(See previous submitted documentation for more info)

Users will come later in the patchset

NOTE: The use of the file relay.h. defines an object "relay".
"Relay" here is in the sense of a relay-race where runners pass the baton from runner to runner.
Also here it is when thread of an Application passes execution to the Server thread and back.
TODO: In future we might define a new scheduler object that
will do the same but without passing through the scheduler at all but relinquishing the reminder of its time slice to the next thread. Maybe we can cut another 1/2 a micro off the latency of an IOP (By avoiding locks and atomics)

[v2 for Linux v5.3]
lin-jump5.3: task_struct cpus_allowed => cpus_mask

---
 fs/zuf/_extern.h  |   16 +
 fs/zuf/_pr.h      |    5 +
 fs/zuf/relay.h    |  104 +++++
 fs/zuf/zuf-core.c | 1077 ++++++++++++++++++++++++++++++++++++++++++++-
 fs/zuf/zuf.h      |   41 ++
 fs/zuf/zus_api.h  |  291 ++++++++++++
 6 files changed, 1533 insertions(+), 1 deletion(-)
 create mode 100644 fs/zuf/relay.h
fs/zuf/_extern.h +16 -0
index 0e8aa52f1259..1f786fc24b85 100644
@@ -27,6 +27,22 @@ void zufc_zts_fini(struct zuf_root_info *zri);
 long zufc_ioctl(struct file *filp, unsigned int cmd, ulong arg);
 int zufc_release(struct inode *inode, struct file *file);
 int zufc_mmap(struct file *file, struct vm_area_struct *vma);
+const char *zuf_op_name(enum e_zufs_operation op);
+
+int zufc_dispatch_mount(struct zuf_root_info *zri, struct zus_fs_info *zus_zfi,
+			enum e_mount_operation operation,
+			struct zufs_ioc_mount *zim);
+
+int __zufc_dispatch(struct zuf_root_info *zri, struct zuf_dispatch_op *zdo);
+static inline
+int zufc_dispatch(struct zuf_root_info *zri, struct zufs_ioc_hdr *hdr,
+		  struct page **pages, uint nump)
+{
+	struct zuf_dispatch_op zdo;
+
+	zuf_dispatch_init(&zdo, hdr, pages, nump);
+	return __zufc_dispatch(zri, &zdo);
+}
 
 /* zuf-root.c */
 int zufr_register_fs(struct super_block *sb, struct zufs_ioc_register_fs *rfs);
fs/zuf/_pr.h +5 -0
index 51924b6bd2a5..2cdb0806687b 100644
@@ -34,6 +34,11 @@
 	} while (0)
 #define zuf_info(s, args ...)          pr_info("~info~ " s, ## args)
 
+#define zuf_err_dispatch(sb, s, args ...) \
+	do { if (zuf_fst(sb)->zri->state != ZUF_ROOT_SERVER_FAILED) \
+		pr_err("[%s:%d] " s, __func__, __LINE__, ## args); \
+	} while (0)
+
 #define zuf_chan_debug(c, s, args...)	pr_debug(c " [%s:%d] " s, __func__, \
 							__LINE__, ## args)
 
fs/zuf/relay.h new file +104 -0

104 lines not on this page · raw message

fs/zuf/zuf-core.c +1076 -1

1,116 lines not on this page · raw message

fs/zuf/zuf.h +41 -0

47 lines not on this page · raw message

fs/zuf/zus_api.h +291 -0

301 lines not on this page · raw message

Signature · 1 line
2.21.0
#6 lore raw

PATCH v2 6/16 zuf: Multy Devices

In reply to Boaz Harrosh

ZUFS supports Multiple block devices per super_block. This here is the devices handling code. At the output a single multi_devices (md.h) object is associated with the mounting super_block.

There are three mode of operations:
* mount with out a device (mount -t FOO none /somepath)

* A single device - The FS stated register_fs_info->dt_offset==-1 No checks are made by Kernel, the single bdev is registered with Kernel's mount_bdev. It is up to the zusFS to check validity

* Multy devices - The FS stated register_fs_info->dt_offset==X

This mode is the main of this patch.
A single device is given on the mount command line. At register_fs_info->dt_offset of this device we look for a zufs_dev_table structure. After all the checks we look there at the device list and open all devices. Any one of the devices may be given on command line. But they will always be opened in DT(Device Table) order. The Device table has the notion of two types of bdevs:
T1 devices - are pmem devices capable of direct_access
T2 devices - are none direct_access devices

All t1 devices are presented as one linear array. in DT order In t1.c we mmap this space for the server to directly access pmem. (In the proper persistent way)

[We do not support any direct_access device, we only support
pmem(s) where the all device can be addressed by a single physical/virtual address. This is checked before mount]

The T2 devices are also grabbed and owned by the super_block A later API will enable the Server to write or transfer buffers from T1 to T2 in a very efficient manner. Also presented as a single linear array in DT order.

Both kind of devices are NUMA aware and the NUMA info is presented to the zusFS for optimal allocation and access.

[v2]
The new gcc compiler does not like that the case /* fall through */ comments comes with other text. So split the comment to two lines to silence the compiler.

[v3]
Do not use __packed on interface structures

---
 fs/zuf/Makefile   |   3 +
 fs/zuf/_extern.h  |   6 +
 fs/zuf/md.c       | 742 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/md.h       | 332 +++++++++++++++++++++
 fs/zuf/md_def.h   | 141 +++++++++
 fs/zuf/super.c    |   6 +
 fs/zuf/t1.c       | 136 +++++++++
 fs/zuf/t2.c       | 356 ++++++++++++++++++++++
 fs/zuf/t2.h       |  68 +++++
 fs/zuf/zuf-core.c |  76 +++++
 fs/zuf/zuf.h      |  54 ++++
 fs/zuf/zus_api.h  |  15 +
 12 files changed, 1935 insertions(+)
 create mode 100644 fs/zuf/md.c
 create mode 100644 fs/zuf/md.h
 create mode 100644 fs/zuf/md_def.h
 create mode 100644 fs/zuf/t1.c
 create mode 100644 fs/zuf/t2.c
 create mode 100644 fs/zuf/t2.h
fs/zuf/Makefile +3 -0
index b08c08e73faa..a247bd85d9aa 100644
@@ -10,6 +10,9 @@
 
 obj-$(CONFIG_ZUFS_FS) += zuf.o
 
+# Infrastructure
+zuf-y += md.o t1.o t2.o
+
 # ZUF core
 zuf-y += zuf-core.o zuf-root.o
 
fs/zuf/_extern.h +6 -0
index 1f786fc24b85..a5929d3d165c 100644
@@ -54,4 +54,10 @@ void zuf_destroy_inodecache(void);
 struct dentry *zuf_mount(struct file_system_type *fs_type, int flags,
 			 const char *dev_name, void *data);
 
+struct super_block *zuf_sb_from_id(struct zuf_root_info *zri, __u64 sb_id,
+				   struct zus_sb_info *zus_sbi);
+
+/* t1.c */
+int zuf_pmem_mmap(struct file *file, struct vm_area_struct *vma);
+
 #endif	/*ndef __ZUF_EXTERN_H__*/
fs/zuf/md.c new file +742 -0

742 lines not on this page · raw message

fs/zuf/md.h new file +332 -0

332 lines not on this page · raw message

fs/zuf/md_def.h new file +141 -0

141 lines not on this page · raw message

fs/zuf/super.c +6 -0
index f7f7798425a9..2248ee74e4c2 100644
@@ -20,6 +20,12 @@
 
 static struct kmem_cache *zuf_inode_cachep;
 
+struct super_block *zuf_sb_from_id(struct zuf_root_info *zri, __u64 sb_id,
+				   struct zus_sb_info *zus_sbi)
+{
+	return NULL;
+}
+
 static void _init_once(void *foo)
 {
 	struct zuf_inode_info *zii = foo;
fs/zuf/t1.c new file +136 -0

136 lines not on this page · raw message

fs/zuf/t2.c new file +356 -0

356 lines not on this page · raw message

fs/zuf/t2.h new file +68 -0

68 lines not on this page · raw message

fs/zuf/zuf-core.c +76 -0

94 lines not on this page · raw message

fs/zuf/zuf.h +54 -0

72 lines not on this page · raw message

fs/zuf/zus_api.h +15 -0
index 6b1fbaf24222..4292a4fa5f1a 100644
@@ -22,6 +22,8 @@
 #include <linux/fiemap.h>
 #include <stddef.h>
 
+#include "md_def.h"
+
 #ifdef __cplusplus
 #define NAMELESS(X) X
 #else
@@ -355,6 +357,19 @@ struct zufs_ioc_numa_map {
 };
 #define ZU_IOC_NUMA_MAP	_IOWR('Z', 13, struct zufs_ioc_numa_map)
 
+struct zufs_ioc_pmem {
+	/* Set by zus */
+	struct zufs_ioc_hdr hdr;
+	__u64 sb_id;
+
+	/* Returned to zus */
+	struct md_dev_table mdt;
+	__u32 dev_index;
+	__u32 ___pad;
+};
+/* GRAB is never ungrabed umount or file close cleans it all */
+#define ZU_IOC_GRAB_PMEM	_IOWR('Z', 14, struct zufs_ioc_pmem)
+
 /* ZT init */
 enum { ZUFS_MAX_ZT_CHANNELS = 4 };
 
Signature · 1 line
2.21.0
#7 lore raw

PATCH v2 7/16 zuf: mounting

In reply to Boaz Harrosh

In this patch we already establish a mounted filesystem.

These are the steps for mounting a zufs Filesystem:

* All devices (Single or Multiple) are opened and established in an md object.

* mount_bdev is called with the main (first) device, in turn fill_supper is called.

* fill_supper dispatches a mount_operation(register_fs_info) to the server with an sb_id of the newly created super_block.

* The Server at the zus mount routine. Will first thing do a GRAB_PMEM(sb_id) ioctl call to establish a special filehandle through which it will have full access to the all of its pmem space. With that it will call the zusFS to continue to inspect the content of devices and mount the FS.

* On return from mount the zusFS returns the root inode info

* fill_supper continues to create a root vfs-inode and returns successfully.

* We now have a mounted super_block, with corresponding super_block objects in the Server.

* Also in this patch global sb operations like statfs show-options and remount. And the umount/destruction of a super_block.

* There is a special support for a "private-mounting" of devices. private-mounting is usually used by the zusFS fschk/mkfs type applications that want a full access and lock-down of its multy-devices. But otherwise wants an exclusive access to these devices. The private mount exposes all the same services to the Server application. But there is no registered/mounted super_block in VFS.
This is a very powerful tool for zusFS development because the same exact code that is used in a running FS is also used for the FS-utils. The code feels exactly the same as a live mount.
(See the zus project for more info)

[v2]
big_alloc now uses a dedicated 8k kmem_cache pool instead of kmalloc because it is used in the IO fast path. And we want guarantied forward progress.

---
 fs/zuf/Makefile   |   2 +-
 fs/zuf/_extern.h  |  10 +-
 fs/zuf/inode.c    |  23 ++
 fs/zuf/super.c    | 806 +++++++++++++++++++++++++++++++++++++++++++++-
 fs/zuf/zuf-core.c |  96 ++++++
 fs/zuf/zuf-root.c |   5 +
 fs/zuf/zuf.h      | 134 ++++++++
 fs/zuf/zus_api.h  |  35 ++
 8 files changed, 1107 insertions(+), 4 deletions(-)
 create mode 100644 fs/zuf/inode.c
fs/zuf/Makefile +1 -1
index a247bd85d9aa..a5800cad73fd 100644
@@ -17,5 +17,5 @@ zuf-y += md.o t1.o t2.o
 zuf-y += zuf-core.o zuf-root.o
 
 # Main FS
-zuf-y += super.o
+zuf-y += super.o inode.o
 zuf-y += module.o
fs/zuf/_extern.h +9 -1
index a5929d3d165c..b1514e5821a2 100644
@@ -51,12 +51,20 @@ int zufr_register_fs(struct super_block *sb, struct zufs_ioc_register_fs *rfs);
 int zuf_init_inodecache(void);
 void zuf_destroy_inodecache(void);
 
+int zuf_8k_cache_init(void);
+void zuf_8k_cache_fini(void);
+
 struct dentry *zuf_mount(struct file_system_type *fs_type, int flags,
 			 const char *dev_name, void *data);
-
+int zuf_private_mount(struct zuf_root_info *zri, struct register_fs_info *rfi,
+		      struct zufs_mount_info *zmi, struct super_block **sb_out);
+int zuf_private_umount(struct zuf_root_info *zri, struct super_block *sb);
 struct super_block *zuf_sb_from_id(struct zuf_root_info *zri, __u64 sb_id,
 				   struct zus_sb_info *zus_sbi);
 
+/* inode.c */
+struct inode *zuf_iget(struct super_block *sb, struct zus_inode_info *zus_ii,
+		       zu_dpp_t _zi, bool *exist);
 /* t1.c */
 int zuf_pmem_mmap(struct file *file, struct vm_area_struct *vma);
 
fs/zuf/inode.c new file +23 -0
new file mode 100644
index 000000000000..a6115289dcda
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * BRIEF DESCRIPTION
+ *
+ * Inode methods (allocate/free/read/write).
+ *
+ * Copyright (c) 2018 NetApp Inc. All rights reserved.
+ *
+ * ZUFS-License: GPL-2.0. See module.c for LICENSE details.
+ *
+ * Authors:
+ *	Boaz Harrosh <[email protected]>
+ *	Sagi Manole <[email protected]>"
+ */
+
+#include "zuf.h"
+
+struct inode *zuf_iget(struct super_block *sb, struct zus_inode_info *zus_ii,
+		       zu_dpp_t _zi, bool *exist)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
fs/zuf/super.c +804 -2

830 lines not on this page · raw message

fs/zuf/zuf-core.c +96 -0

120 lines not on this page · raw message

fs/zuf/zuf-root.c +5 -0
index ea7eb810ea9d..ecf240bd3e3f 100644
@@ -405,6 +405,10 @@ int __init zuf_root_init(void)
 {
 	int err = zuf_init_inodecache();
 
+	if (unlikely(err))
+		return err;
+
+	err = zuf_8k_cache_init();
 	if (unlikely(err))
 		return err;
 
@@ -431,6 +435,7 @@ static void __exit zuf_root_exit(void)
 {
 	unregister_filesystem(&zufr_type);
 	kset_unregister(zufr_kset);
+	zuf_8k_cache_fini();
 	zuf_destroy_inodecache();
 }
 
fs/zuf/zuf.h +134 -0

152 lines not on this page · raw message

fs/zuf/zus_api.h +35 -0
index 4292a4fa5f1a..1af3bd016453 100644
@@ -330,6 +330,17 @@ struct  zufs_ioc_mount {
 };
 #define ZU_IOC_MOUNT		_IOWR('Z', 11, struct zufs_ioc_mount)
 
+/* Mount locally with a zus-runner process */
+#define ZUFS_PMDEV_OPT "zpmdev"
+struct zufs_ioc_mount_private {
+	struct zufs_ioc_hdr	hdr;
+	__u32			mount_fd; /* kernel cookie */
+	__u32			is_umount; /* true or false */
+	struct register_fs_info	rfi;
+	struct zufs_mount_info	zmi; /* must be last */
+};
+#define ZU_IOC_PRIVATE_MOUNT	_IOWR('Z', 12, struct zufs_ioc_mount_private)
+
 /* pmem  */
 struct zufs_cpu_set {
 	ulong bits[16];
@@ -432,7 +443,31 @@ enum e_zufs_operation {
 	ZUFS_OP_NULL		= 0,
 	ZUFS_OP_BREAK		= 1,	/* Kernel telling Server to exit */
 
+	ZUFS_OP_STATFS		= 2,
+	ZUFS_OP_SHOW_OPTIONS	= 3,
+
 	ZUFS_OP_MAX_OPT,
 };
 
+#define ZUFS_MO_MAX	512
+
+struct zufs_ioc_mount_options {
+	struct zufs_ioc_hdr hdr;
+	/* IN */
+	struct zus_sb_info *zus_sbi;
+
+	/* OUT */
+	char	buf[0];
+};
+
+/* ZUFS_OP_STATFS */
+struct zufs_ioc_statfs {
+	struct zufs_ioc_hdr hdr;
+	/* IN */
+	struct zus_sb_info *zus_sbi;
+
+	/* OUT */
+	struct statfs64 statfs_out;
+};
+
 #endif /* _LINUX_ZUFS_API_H */
Signature · 1 line
2.21.0
#8 lore raw

PATCH v2 8/16 zuf: Namei and directory operations

In reply to Boaz Harrosh

Introducing Creation/deletion of files
Directory add/remove
Other namei operations

This is all a very STD Kernel way of doing things. Each VFS operation is packed and dispatched to Server. After dispatch return, pushing results into Kernel structures

NOTE: The use of a zufs_inode communication structure that is returned as a zufs_dpp_t (Dual port pointer) Both Kernel and Server can read/write to this object. If Kernel modifies this object it is always before the dispatch so server can persist the changes. It is also used by Server to return new info to be updated into the vfs_inode.
In a pmem system this object can be directly pointing to storage.

---
 fs/zuf/Makefile    |   2 +-
 fs/zuf/_extern.h   |  41 ++++
 fs/zuf/directory.c | 100 ++++++++
 fs/zuf/file.c      |  31 +++
 fs/zuf/inode.c     | 561 ++++++++++++++++++++++++++++++++++++++++++++-
 fs/zuf/namei.c     | 402 ++++++++++++++++++++++++++++++++
 fs/zuf/super.c     |   2 +
 fs/zuf/zuf-core.c  |  10 +
 fs/zuf/zuf.h       |  63 +++++
 fs/zuf/zus_api.h   |  94 ++++++++
 10 files changed, 1304 insertions(+), 2 deletions(-)
 create mode 100644 fs/zuf/directory.c
 create mode 100644 fs/zuf/file.c
 create mode 100644 fs/zuf/namei.c
fs/zuf/Makefile +1 -1
index a5800cad73fd..2bfed45723e3 100644
@@ -17,5 +17,5 @@ zuf-y += md.o t1.o t2.o
 zuf-y += zuf-core.o zuf-root.o
 
 # Main FS
-zuf-y += super.o inode.o
+zuf-y += super.o inode.o directory.o namei.o file.o
 zuf-y += module.o
fs/zuf/_extern.h +41 -0

51 lines not on this page · raw message

fs/zuf/directory.c new file +100 -0

100 lines not on this page · raw message

fs/zuf/file.c new file +31 -0
new file mode 100644
index 000000000000..619dada43666
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * BRIEF DESCRIPTION
+ *
+ * File operations for files.
+ *
+ * Copyright (c) 2018 NetApp Inc. All rights reserved.
+ *
+ * ZUFS-License: GPL-2.0. See module.c for LICENSE details.
+ *
+ * Authors:
+ *	Boaz Harrosh <[email protected]>
+ *	Sagi Manole <[email protected]>"
+ */
+
+#include "zuf.h"
+
+long __zuf_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)
+{
+	return -ENOTSUPP;
+}
+
+const struct file_operations zuf_file_operations = {
+	.open			= generic_file_open,
+};
+
+const struct inode_operations zuf_file_inode_operations = {
+	.setattr	= zuf_setattr,
+	.getattr	= zuf_getattr,
+	.update_time	= zuf_update_time,
+};
fs/zuf/inode.c +560 -1

571 lines not on this page · raw message

fs/zuf/namei.c new file +402 -0

402 lines not on this page · raw message

fs/zuf/super.c +2 -0
index 01927deb5013..abd7e6cb2a4a 100644
@@ -784,6 +784,8 @@ void zuf_destroy_inodecache(void)
 static struct super_operations zuf_sops = {
 	.alloc_inode	= zuf_alloc_inode,
 	.destroy_inode	= zuf_destroy_inode,
+	.write_inode	= zuf_write_inode,
+	.evict_inode	= zuf_evict_inode,
 	.put_super	= zuf_put_super,
 	.freeze_fs	= zuf_update_s_wtime,
 	.unfreeze_fs	= zuf_update_s_wtime,
fs/zuf/zuf-core.c +10 -0
index a417f9463682..48dd7b665064 100644
@@ -65,6 +65,16 @@ const char *zuf_op_name(enum e_zufs_operation op)
 		CASE_ENUM_NAME(ZUFS_OP_BREAK);
 		CASE_ENUM_NAME(ZUFS_OP_STATFS);
 		CASE_ENUM_NAME(ZUFS_OP_SHOW_OPTIONS);
+
+		CASE_ENUM_NAME(ZUFS_OP_NEW_INODE);
+		CASE_ENUM_NAME(ZUFS_OP_FREE_INODE);
+		CASE_ENUM_NAME(ZUFS_OP_EVICT_INODE);
+
+		CASE_ENUM_NAME(ZUFS_OP_LOOKUP);
+		CASE_ENUM_NAME(ZUFS_OP_ADD_DENTRY);
+		CASE_ENUM_NAME(ZUFS_OP_REMOVE_DENTRY);
+		CASE_ENUM_NAME(ZUFS_OP_RENAME);
+		CASE_ENUM_NAME(ZUFS_OP_SETATTR);
 	case ZUFS_OP_MAX_OPT:
 	default:
 		return "UNKNOWN";
fs/zuf/zuf.h +63 -0

75 lines not on this page · raw message

fs/zuf/zus_api.h +94 -0

104 lines not on this page · raw message

Signature · 1 line
2.21.0
#9 lore raw

PATCH v2 9/16 zuf: readdir operation

In reply to Boaz Harrosh

Implements the file_operations->iterate_shared via info returned from Server.

Establish protocol with Server for readdir.

The Server fills a zuf allocated buffer (up to 4M at a time) which will contain a zufs encoded dir entries. It will then call the proper emit vector to fill the caller buffer. The buffer is passed to Server not as part of the zufs_ioc_readdir struct but maps this buffer directly into Server space via the zt_map_pages facility.

[v2]
Fix the gcc warning:
directory.c:86:1: warning: the frame size of 8576 bytes is
larger than 8192 bytes
Fix it by allocating the pages array, which was on stack as part of the allocation we already do for the readdir buffer

---
 fs/zuf/directory.c | 69 +++++++++++++++++++++++++++++++++++-
 fs/zuf/zuf-core.c  |  2 ++
 fs/zuf/zus_api.h   | 88 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 158 insertions(+), 1 deletion(-)
fs/zuf/directory.c +68 -1
index 5624e05f96e5..7417aeb77773 100644
@@ -19,7 +19,74 @@
 
 static int zuf_readdir(struct file *file, struct dir_context *ctx)
 {
-	return -ENOTSUPP;
+	struct inode *inode = file_inode(file);
+	struct super_block *sb = inode->i_sb;
+	loff_t i_size = i_size_read(inode);
+	struct zufs_ioc_readdir ioc_readdir = {
+		.hdr.in_len = sizeof(ioc_readdir),
+		.hdr.out_len = sizeof(ioc_readdir),
+		.hdr.operation = ZUFS_OP_READDIR,
+		.dir_ii = ZUII(inode)->zus_ii,
+	};
+	struct zufs_readdir_iter rdi;
+	struct page **pages;
+	struct zufs_dir_entry *zde;
+	void *addr, *__a;
+	uint nump, i;
+	int err;
+
+	if (ctx->pos && i_size <= ctx->pos)
+		return 0;
+	if (!i_size)
+		i_size = PAGE_SIZE; /* Just for the . && .. */
+	if (i_size - ctx->pos < PAGE_SIZE)
+		ioc_readdir.hdr.len = PAGE_SIZE;
+	else
+		ioc_readdir.hdr.len = min_t(loff_t, i_size - ctx->pos,
+					    ZUS_API_MAP_MAX_SIZE);
+	nump = md_o2p_up(ioc_readdir.hdr.len);
+	/* Allocating both readdir buffer and the pages-array.
+	 * Pages array is at end
+	 */
+	addr = vzalloc(md_p2o(nump) + nump * sizeof(*pages));
+	if (unlikely(!addr))
+		return -ENOMEM;
+
+	WARN_ON((ulong)addr & (PAGE_SIZE - 1));
+
+	pages = addr + md_p2o(nump);
+	__a = addr;
+	for (i = 0; i < nump; ++i) {
+		pages[i] = vmalloc_to_page(__a);
+		__a += PAGE_SIZE;
+	}
+
+more:
+	ioc_readdir.pos = ctx->pos;
+
+	err = zufc_dispatch(ZUF_ROOT(SBI(sb)), &ioc_readdir.hdr, pages, nump);
+	if (unlikely(err && err != -EINTR)) {
+		zuf_err_dispatch(sb, "zufc_dispatch failed => %d\n", err);
+		goto out;
+	}
+
+	zufs_readdir_iter_init(&rdi, &ioc_readdir, addr);
+	while ((zde = zufs_next_zde(&rdi)) != NULL) {
+		zuf_dbg_verbose("%s pos=0x%lx\n",
+				zde->zstr.name, (ulong)zde->pos);
+		ctx->pos = zde->pos;
+		if (!dir_emit(ctx, zde->zstr.name, zde->zstr.len, zde->ino,
+			      zde->type))
+			goto out;
+	}
+	ctx->pos = ioc_readdir.pos;
+	if (ioc_readdir.more) {
+		zuf_dbg_err("more\n");
+		goto more;
+	}
+out:
+	vfree(addr);
+	return err;
 }
 
 /*
fs/zuf/zuf-core.c +2 -0
index 48dd7b665064..c0049c1d5ba3 100644
@@ -74,6 +74,8 @@ const char *zuf_op_name(enum e_zufs_operation op)
 		CASE_ENUM_NAME(ZUFS_OP_ADD_DENTRY);
 		CASE_ENUM_NAME(ZUFS_OP_REMOVE_DENTRY);
 		CASE_ENUM_NAME(ZUFS_OP_RENAME);
+		CASE_ENUM_NAME(ZUFS_OP_READDIR);
+
 		CASE_ENUM_NAME(ZUFS_OP_SETATTR);
 	case ZUFS_OP_MAX_OPT:
 	default:
fs/zuf/zus_api.h +88 -0

100 lines not on this page · raw message

Signature · 1 line
2.21.0
#10 lore raw

PATCH v2 10/16 zuf: symlink

In reply to Boaz Harrosh

The symlink support is all hidden within the creation/open of the inode.

As part of ZUFS_OP_NEW_INODE we also send the requested content of the symlink for storage.

On an open of an existing symlink the link information is returned within the zufs_inode structure via a zufs_dpp_t pointer. (See Documentation about zufs_dpp_t pointers)

---
 fs/zuf/Makefile  |  2 +-
 fs/zuf/_extern.h |  7 +++++
 fs/zuf/inode.c   |  7 +++++
 fs/zuf/namei.c   | 27 ++++++++++++++++++
 fs/zuf/symlink.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 fs/zuf/symlink.c
fs/zuf/Makefile +1 -1
index 2bfed45723e3..04c31b7bb9ff 100644
@@ -17,5 +17,5 @@ zuf-y += md.o t1.o t2.o
 zuf-y += zuf-core.o zuf-root.o
 
 # Main FS
-zuf-y += super.o inode.o directory.o namei.o file.o
+zuf-y += super.o inode.o directory.o namei.o file.o symlink.o
 zuf-y += module.o
fs/zuf/_extern.h +7 -0
index 50887792bf42..95413f65c47f 100644
@@ -88,6 +88,10 @@ void zuf_set_inode_flags(struct inode *inode, struct zus_inode *zi);
 int zuf_add_dentry(struct inode *dir, struct qstr *str, struct inode *inode);
 int zuf_remove_dentry(struct inode *dir, struct qstr *str, struct inode *inode);
 
+/* symlink.c */
+uint zuf_prepare_symname(struct zufs_ioc_new_inode *ioc_new_inode,
+			const char *symname, ulong len, struct page *pages[2]);
+
 /* t1.c */
 int zuf_pmem_mmap(struct file *file, struct vm_area_struct *vma);
 
@@ -109,4 +113,7 @@ extern const struct inode_operations zuf_special_inode_operations;
 /* dir.c */
 extern const struct file_operations zuf_dir_operations;
 
+/* symlink.c */
+extern const struct inode_operations zuf_symlink_inode_operations;
+
 #endif	/*ndef __ZUF_EXTERN_H__*/
fs/zuf/inode.c +7 -0
index 88cb1937c223..bf3f8b27f918 100644
@@ -83,6 +83,9 @@ static void _set_inode_from_zi(struct inode *inode, struct zus_inode *zi)
 		inode->i_op = &zuf_dir_inode_operations;
 		inode->i_fop = &zuf_dir_operations;
 		break;
+	case S_IFLNK:
+		inode->i_op = &zuf_symlink_inode_operations;
+		break;
 	case S_IFBLK:
 	case S_IFCHR:
 	case S_IFIFO:
@@ -348,6 +351,10 @@ struct inode *zuf_new_inode(struct inode *dir, umode_t mode,
 	if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
 	    S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
 		init_special_inode(inode, mode, rdev_or_isize);
+	} else if (symname) {
+		inode->i_size = rdev_or_isize;
+		nump = zuf_prepare_symname(&ioc_new_inode, symname,
+					   rdev_or_isize, pages);
 	}
 
 	err = _set_zi_from_inode(dir, &ioc_new_inode.zi, inode);
fs/zuf/namei.c +27 -0
index 299134ca7c07..e78aa04f10d5 100644
@@ -164,6 +164,32 @@ static int zuf_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
 	return 0;
 }
 
+static int zuf_symlink(struct inode *dir, struct dentry *dentry,
+		       const char *symname)
+{
+	struct inode *inode;
+	ulong len;
+
+	zuf_dbg_vfs("[%ld] de->name=%s symname=%s\n",
+			dir->i_ino, dentry->d_name.name, symname);
+
+	len = strlen(symname);
+	if (len + 1 > ZUFS_MAX_SYMLINK)
+		return -ENAMETOOLONG;
+
+	inode = zuf_new_inode(dir, S_IFLNK|S_IRWXUGO, &dentry->d_name,
+			       symname, len, false);
+	if (IS_ERR(inode))
+		return PTR_ERR(inode);
+
+	inode->i_op = &zuf_symlink_inode_operations;
+	inode->i_mapping->a_ops = &zuf_aops;
+
+	_instantiate_unlock(dentry, inode);
+
+	return 0;
+}
+
 static int zuf_link(struct dentry *dest_dentry, struct inode *dir,
 		    struct dentry *dentry)
 {
@@ -385,6 +411,7 @@ const struct inode_operations zuf_dir_inode_operations = {
 	.lookup		= zuf_lookup,
 	.link		= zuf_link,
 	.unlink		= zuf_unlink,
+	.symlink	= zuf_symlink,
 	.mkdir		= zuf_mkdir,
 	.rmdir		= zuf_rmdir,
 	.mknod		= zuf_mknod,
fs/zuf/symlink.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.21.0
#11 lore raw

PATCH v2 11/16 zuf: Write/Read implementation

In reply to Boaz Harrosh

zufs Has two ways to do IO.

1. The elegant way:
By mapping application buffers into Server VM. This is much simpler to implement by zusFS. But is slow and does not scale well.

2. The fast way: (called NIO)
Server returns physical block information. And the pmem_memcpy is done in Kernel.

This way is more complicated. Each block needs to ZUFS_GET_MULTI But also ZUFS_PUT_MULTI to indicate that Kernel has finished the copy, and pmem block may be recycled.
But if we will go to server and back twice for each IOP this will kill our performance. So what we do is the pigi_put mechanisim (See zuf-core.c). pigi_put is a way to delay the put operation for later so when a new operation is going to Server it will take on the way all accumulated put operations. So in one go I might fetch new block info as well as PUT the previous IO. Don't worry all this is done zuf-core style without any locks or atomics. There are times that Server may request an immediate PUT and/or keep the ZT-channel locked for guaranty forward progress.

It is up to the zusFS to decide which mode it wants to operate in
[1] or [2] above. And more flags govern aspects of the IO requested.

The dispatch to the server can operate on buffers up to ZUS_API_MAP_MAX_SIZE (4M). Any bigger operations are split up and dispatched at this size.

Also if a multy-segments aio is used each segment is dispatched on its own.

rw.c here also includes some operations for mmap. Will be used in next patch.

The fallocate operation with its various mode flags is also dispatched through the rw.c IO API because it might need to do some t1/t2 IO as part of the operation. If it is for COW of cloned inodes or read/write of the unaligned edges. zufs also implements truncate via a private fallocate flag.

There is also code for comparing two buffers for the implementation of the dedup operation.

Also in this patch the facility to SWAP on a zufs system.

There is also an IOCTL fasility to execute IO (ZU_IOC_IOMAP_EXEC) from a Server background threads. We use this in Netapp for tiering down cold blocks to slower storage.
Both ZU_IOC_IOMAP_EXEC and the IO despatch operate on facility we call zufs_iomap which is a varlen buffer that may request and encode many types of operations and block/memory targets for IO. It is kind of an IO executor of sorts. zusFS encodes such iomap to tell Kernel what needs to be done.

[v2]
zuf: Range of _IO_gm_inner must fit API (PXS-5151)
Zuf must never request pages which may fall out-of-range of
ZUS_API_MAP_MAX_PAGES. When IO request is not page-aligned, limit size based on start offset.

[v3]
zufc: bad bugs in zufc_goose_all_zts

* The BAD Bug was that we called the internal smp_call_function instead of the proper on_each_cpu.
This was bad because smp_call_function calls all other CPUs but us. Anyway the proper public API for this is on_each_cpu.

* Another BUG is that zufc_goose_all_zts needs to be always called with an inode. This is because we are assuming that we are holding the inode_w_lock and no more puts can come in parallel to the goose_all.

* In clone the goose target is the destination file which is going to be truncated. (See above we must have a locked inode at hand)

* Call zufc_goose_all_zts under the inode_w_lock in evict.

* One more change is to *not* relay on Server to turn off the ZUFS_H_HAS_PIGY_PUT flag. We will use this later to fix another theoretical Race window with pigi_put
(In fact there is a zus patch to stop resetting that bit)

[v4]
Remove the swap activate code. It will come in later Kernels. This is because to do it properly we should send a small patch to Kernel so to not force the FS to use page_cache. The code had an Hack to bypass this bug. But I rather remove the code instead.

[v5]
Fix the warning of type:
warning: the frame size of 8712 bytes is larger than 8192 bytes

We allocate the maximum stack space allowed by the Kernel configuration, without warning. If the needed space fits in the stack it is used. If not we allocate from a new dedicated kmem_cache an 8K buffer to store our block-numbers. 8k is the maximum allowed in the zufs API which is 1024 data blocks,
The above logic is hidden under the big_alloc facility that was already used in other places.

---
 fs/zuf/Makefile   |   1 +
 fs/zuf/_extern.h  |  22 ++
 fs/zuf/file.c     |  73 ++++
 fs/zuf/inode.c    |  13 +
 fs/zuf/rw.c       | 959 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf-core.c | 400 ++++++++++++++++++-
 fs/zuf/zuf.h      |   7 +
 fs/zuf/zus_api.h  | 251 ++++++++++++
 8 files changed, 1724 insertions(+), 2 deletions(-)
 create mode 100644 fs/zuf/rw.c
fs/zuf/Makefile +1 -0
index 04c31b7bb9ff..23bc3791a001 100644
@@ -17,5 +17,6 @@ zuf-y += md.o t1.o t2.o
 zuf-y += zuf-core.o zuf-root.o
 
 # Main FS
+zuf-y += rw.o
 zuf-y += super.o inode.o directory.o namei.o file.o symlink.o
 zuf-y += module.o
fs/zuf/_extern.h +22 -0
index 95413f65c47f..745d0cc9e719 100644
@@ -43,6 +43,9 @@ int zufc_dispatch(struct zuf_root_info *zri, struct zufs_ioc_hdr *hdr,
 	zuf_dispatch_init(&zdo, hdr, pages, nump);
 	return __zufc_dispatch(zri, &zdo);
 }
+int zufc_pigy_put(struct zuf_root_info *zri, struct zuf_dispatch_op *zdo,
+		  struct zufs_ioc_IO *io, uint iom_n, ulong *bns, bool do_now);
+void zufc_goose_all_zts(struct zuf_root_info *zri, struct inode *inode);
 
 /* zuf-root.c */
 int zufr_register_fs(struct super_block *sb, struct zufs_ioc_register_fs *rfs);
@@ -92,6 +95,25 @@ int zuf_remove_dentry(struct inode *dir, struct qstr *str, struct inode *inode);
 uint zuf_prepare_symname(struct zufs_ioc_new_inode *ioc_new_inode,
 			const char *symname, ulong len, struct page *pages[2]);
 
+/* rw.c */
+int zuf_rw_read_page(struct zuf_sb_info *sbi, struct inode *inode,
+		     struct page *page, u64 filepos);
+ssize_t zuf_rw_read_iter(struct super_block *sb, struct inode *inode,
+			 struct kiocb *kiocb, struct iov_iter *ii);
+ssize_t zuf_rw_write_iter(struct super_block *sb, struct inode *inode,
+			  struct kiocb *kiocb, struct iov_iter *ii);
+int _zufs_IO_get_multy(struct zuf_sb_info *sbi, struct inode *inode,
+		       loff_t pos, ulong len, struct _io_gb_multy *io_gb);
+void _zufs_IO_put_multy(struct zuf_sb_info *sbi, struct inode *inode,
+			struct _io_gb_multy *io_gb);
+int zuf_rw_fallocate(struct inode *inode, uint mode, loff_t offset, loff_t len);
+int zuf_iom_execute_sync(struct super_block *sb, struct inode *inode,
+			 __u64 *iom_e, uint iom_n);
+int zuf_iom_execute_async(struct super_block *sb, struct zus_iomap_build *iomb,
+			 __u64 *iom_e_user, uint iom_n);
+int zuf_rw_file_range_compare(struct inode *i_in, loff_t pos_in,
+			      struct inode *i_out, loff_t pos_out, loff_t len);
+
 /* t1.c */
 int zuf_pmem_mmap(struct file *file, struct vm_area_struct *vma);
 
fs/zuf/file.c +73 -0

87 lines not on this page · raw message

fs/zuf/inode.c +13 -0
index bf3f8b27f918..27660979ed6f 100644
@@ -287,6 +287,8 @@ void zuf_evict_inode(struct inode *inode)
 
 		zuf_w_lock(zii);
 
+		zufc_goose_all_zts(ZUF_ROOT(SBI(sb)), inode);
+
 		zuf_evict_dispatch(sb, zii->zus_ii, ZUFS_OP_FREE_INODE, 0);
 
 		inode->i_mtime = inode->i_ctime = current_time(inode);
@@ -298,6 +300,8 @@ void zuf_evict_inode(struct inode *inode)
 
 		zuf_smw_lock(zii);
 
+		zufc_goose_all_zts(ZUF_ROOT(SBI(sb)), inode);
+
 		zuf_evict_dispatch(sb, zii->zus_ii, ZUFS_OP_EVICT_INODE, 0);
 
 		zuf_smw_unlock(zii);
@@ -585,5 +589,14 @@ void zuf_set_inode_flags(struct inode *inode, struct zus_inode *zi)
 		inode_has_no_xattr(inode);
 }
 
+/* direct_IO is not called. We set an empty one so open(O_DIRECT) will be happy
+ */
+static ssize_t zuf_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
+{
+	WARN_ON(1);
+	return 0;
+}
+
 const struct address_space_operations zuf_aops = {
+	.direct_IO		= zuf_direct_IO,
 };
fs/zuf/rw.c new file +959 -0

959 lines not on this page · raw message

fs/zuf/zuf-core.c +398 -2

489 lines not on this page · raw message

fs/zuf/zuf.h +7 -0
index 2d5327e1d2b1..2c57c51a2099 100644
@@ -402,6 +402,13 @@ static inline int zuf_flt_to_err(vm_fault_t flt)
 	return -EACCES;
 }
 
+struct _io_gb_multy {
+	struct zuf_dispatch_op zdo;
+	struct zufs_ioc_IO IO;
+	ulong iom_n;
+	ulong *bns;
+};
+
 /* Keep this include last thing in file */
 #include "_extern.h"
 
fs/zuf/zus_api.h +251 -0

268 lines not on this page · raw message

Signature · 1 line
2.21.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Re: [PATCH 11/16] zuf: Write/Read implementation

Quoted 5 lines · Anna
Quoted 1 line

+ return size ?: ret;

It looks like you're returning "ret" if the ternary evaluates to false, but it's not clear to me what is returned if it evaluates to true. It's possible it's okay, but I just don't know enough about how ternaries work in this case.

It's an unloved, unwnted GNU extension. See
https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html

It's really no better than writing:

	return size ? size : ret;

or even better:

	if (size)
		return size;
	return ret;
#14 lore raw

Re: [PATCH 11/16] zuf: Write/Read implementation

Quoted 12 lines · Matthew Wilcox
Quoted 5 lines · Anna
Quoted 1 line

+ return size ?: ret;

It looks like you're returning "ret" if the ternary evaluates to false, but it's not clear to me what is returned if it evaluates to true. It's possible it's okay, but I just don't know enough about how ternaries work in this case.

It's an unloved, unwnted GNU extension. See
https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html

It's really no better than writing:

Quoted 8 lines
	return size ? size : ret;

or even better:

	if (size)
		return size;
	return ret;

OK Cool thanks will do
Boaz

#15 lore raw

Re: [PATCH 11/16] zuf: Write/Read implementation

In reply to a message not in the archive
Quoted 4 lines · Anna

Hi Boaz,

Quoted 1 line · Boaz Harrosh

zufs Has two ways to do IO.

<>

Quoted 4 lines

fs/zuf/rw.c line 72

Quoted 4 lines
fs/zuf/rw.c new file +4 -0
+static int rw_overflow_handler(struct zuf_dispatch_op *zdo, void *arg,
+                              ulong max_bytes)
+{
+       struct zufs_ioc_IO *io = container_of(zdo->hdr, typeof(*io), hdr);

This one is setting the typed pointer @io to be the same of what @zdo->hdr is

Quoted 4 lines

fs/zuf/rw.c line 76

Quoted 4 lines
fs/zuf/rw.c new file +4 -0
+       struct zufs_ioc_IO *io_user = arg;
+       int err;
+
+       *io = *io_user;

This one is deep copying the full size structure pointed to by io_user to the space pointed to by io. (same as zdo->hdr)

Same as memcpy(io, io_user, sizeof(*io))

Quoted 5 lines

It looks like you're setting *io using the container_of() macro a few lines above, and then overwriting it here without ever using it. Can you remove one of these to make it clearer which one you meant to use?

These are not redundant its the confusing C thing where declarations of pointers + assignment means the pointer and not the content.

This code is correct

Quoted 11 lines
Quoted 11 lines
fs/zuf/rw.c new file +11 -0
+
+       err = _ioc_bounds_check(&io->ziom, &io_user->ziom, arg + max_bytes);
+       if (unlikely(err))
+               return err;
+
+       if ((io->hdr.err == -EZUFS_RETRY) &&
+           io->ziom.iom_n && _zufs_iom_pop(io->iom_e)) {
+
+               zuf_dbg_rw(
+                       "[%s]zuf_iom_execute_sync(%d) max=0x%lx iom_e[%d] => %d\n",
+                       zuf_op_name(io->hdr.operation), io->ziom.iom_n,
Quoted 8 lines

fs/zuf/rw.c line 95

Quoted 8 lines
fs/zuf/rw.c new file +8 -0
+                       max_bytes, _zufs_iom_opt_type(io_user->iom_e),
+                       io->hdr.err);
+
+               io->hdr.err = zuf_iom_execute_sync(zdo->sb, zdo->inode,
+                                                  io_user->iom_e,
+                                                  io->ziom.iom_n);
+               return EZUF_RETRY_DONE;
+       }

<>

Quoted 30 lines
Quoted 30 lines
fs/zuf/rw.c new file +30 -0
+static ssize_t _IO_gm(struct zuf_sb_info *sbi, struct inode *inode,
+                     ulong *on_stack, uint max_on_stack,
+                     struct iov_iter *ii, struct kiocb *kiocb,
+                     struct file_ra_state *ra, uint rw)
+{
+       ssize_t size = 0;
+       ssize_t ret = 0;
+       enum big_alloc_type bat;
+       ulong *bns;
+       uint max_bns = min_t(uint,
+               md_o2p_up(iov_iter_count(ii) + (kiocb->ki_pos & ~PAGE_MASK)),
+               ZUS_API_MAP_MAX_PAGES);
+
+       bns = big_alloc(max_bns * sizeof(ulong), max_on_stack, on_stack,
+                       GFP_NOFS, &bat);
+       if (unlikely(!bns)) {
+               zuf_err("life was more simple on the stack max_bns=%d\n",
+                       max_bns);
+               return -ENOMEM;
+       }
+
+       while (iov_iter_count(ii)) {
+               ret = _IO_gm_inner(sbi, inode, bns, max_bns, ii, ra,
+                                  kiocb->ki_pos, rw);
+               if (unlikely(ret < 0))
+                       break;
+
+               kiocb->ki_pos += ret;
+               size += ret;
+       }
Quoted 9 lines

fs/zuf/rw.c line 619

Quoted 4 lines
fs/zuf/rw.c new file +4 -0
+
+       big_free(bns, bat);
+
+       return size ?: ret;

It looks like you're returning "ret" if the ternary evaluates to false, but it's not clear to me what is returned if it evaluates to true. It's possible it's okay, but I just don't know enough about how ternaries work in this case.

Yes Thanks, Will fix. Not suppose to use this in the Kernel.

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+

<>

Quoted 32 lines
Quoted 19 lines
fs/zuf/rw.c new file +19 -0
+int zuf_iom_execute_sync(struct super_block *sb, struct inode *inode,
+                        __u64 *iom_e_user, uint iom_n)
+{
+       struct zuf_sb_info *sbi = SBI(sb);
+       struct t2_io_state rd_tis = {};
+       struct t2_io_state wr_tis = {};
+       struct _iom_exec_info iei = {};
+       int err, err_r, err_w;
+
+       t2_io_begin(sbi->md, READ, NULL, 0, -1, &rd_tis);
+       t2_io_begin(sbi->md, WRITE, NULL, 0, -1, &wr_tis);
+
+       iei.sb = sb;
+       iei.inode = inode;
+       iei.rd_tis = &rd_tis;
+       iei.wr_tis = &wr_tis;
+       iei.iom_e = iom_e_user;
+       iei.iom_n = iom_n;
+       iei.print = 0;

fs/zuf/rw.c line 951

Quoted 10 lines
fs/zuf/rw.c new file +10 -0
+
+       err = _iom_execute_inline(&iei);
+
+       err_r = t2_io_end(&rd_tis, true);
+       err_w = t2_io_end(&wr_tis, true);
+
+       /* TODO: not sure if OK when _iom_execute return with -ENOMEM
+        * In such a case, we might be better of skiping t2_io_ends.
+        */
+       return err ?: (err_r ?: err_w);

Same question here.

Quoted 3 lines

Thanks,
Anna

Yes Will fix

Thanks Anna
Can I put Reviewed-by on this patch?

Quoted 1 line
Quoted 1 line

+}

Much obliged
Boaz

#16 lore raw

Re: [PATCH 11/16] zuf: Write/Read implementation

Quoted 145 lines · Boaz Harrosh

NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 4 lines · Anna

Hi Boaz,

Quoted 1 line · Boaz Harrosh

zufs Has two ways to do IO.

<>

Quoted 4 lines

fs/zuf/rw.c line 72

Quoted 4 lines
fs/zuf/rw.c new file +4 -0
+static int rw_overflow_handler(struct zuf_dispatch_op *zdo, void *arg,
+                              ulong max_bytes)
+{
+       struct zufs_ioc_IO *io = container_of(zdo->hdr, typeof(*io), hdr);

This one is setting the typed pointer @io to be the same of what @zdo->hdr is

Quoted 4 lines

fs/zuf/rw.c line 76

Quoted 4 lines
fs/zuf/rw.c new file +4 -0
+       struct zufs_ioc_IO *io_user = arg;
+       int err;
+
+       *io = *io_user;

This one is deep copying the full size structure pointed to by io_user to the space pointed to by io. (same as zdo->hdr)

Same as memcpy(io, io_user, sizeof(*io))

Quoted 6 lines

It looks like you're setting *io using the container_of() macro a few lines above, and then
overwriting it here without ever using it. Can you remove one of these to make it clearer which
one you meant to use?

These are not redundant its the confusing C thing where declarations of pointers + assignment means the pointer and not the content.

This code is correct

Quoted 13 lines
Quoted 13 lines
(quoted diff) +2 -0
+
+       err = _ioc_bounds_check(&io->ziom, &io_user->ziom, arg +

max_bytes);

fs/zuf/rw.c new file +8 -0
+       if (unlikely(err))
+               return err;
+
+       if ((io->hdr.err == -EZUFS_RETRY) &&
+           io->ziom.iom_n && _zufs_iom_pop(io->iom_e)) {
+
+               zuf_dbg_rw(
+                       "[%s]zuf_iom_execute_sync(%d) max=0x%lx iom_e[%d]

=> %d\n",
+ zuf_op_name(io->hdr.operation), io->ziom.iom_n,

Quoted 8 lines

fs/zuf/rw.c line 95

Quoted 8 lines
fs/zuf/rw.c new file +8 -0
+                       max_bytes, _zufs_iom_opt_type(io_user->iom_e),
+                       io->hdr.err);
+
+               io->hdr.err = zuf_iom_execute_sync(zdo->sb, zdo->inode,
+                                                  io_user->iom_e,
+                                                  io->ziom.iom_n);
+               return EZUF_RETRY_DONE;
+       }

<>

Quoted 33 lines
Quoted 33 lines
fs/zuf/rw.c new file +11 -0
+static ssize_t _IO_gm(struct zuf_sb_info *sbi, struct inode *inode,
+                     ulong *on_stack, uint max_on_stack,
+                     struct iov_iter *ii, struct kiocb *kiocb,
+                     struct file_ra_state *ra, uint rw)
+{
+       ssize_t size = 0;
+       ssize_t ret = 0;
+       enum big_alloc_type bat;
+       ulong *bns;
+       uint max_bns = min_t(uint,
+               md_o2p_up(iov_iter_count(ii) + (kiocb->ki_pos &

~PAGE_MASK)),

fs/zuf/rw.c new file +21 -0
+               ZUS_API_MAP_MAX_PAGES);
+
+       bns = big_alloc(max_bns * sizeof(ulong), max_on_stack, on_stack,
+                       GFP_NOFS, &bat);
+       if (unlikely(!bns)) {
+               zuf_err("life was more simple on the stack max_bns=%d\n",
+                       max_bns);
+               return -ENOMEM;
+       }
+
+       while (iov_iter_count(ii)) {
+               ret = _IO_gm_inner(sbi, inode, bns, max_bns, ii, ra,
+                                  kiocb->ki_pos, rw);
+               if (unlikely(ret < 0))
+                       break;
+
+               kiocb->ki_pos += ret;
+               size += ret;
+       }
+
+       big_free(bns, bat);
Quoted 9 lines

fs/zuf/rw.c line 619

Quoted 2 lines
fs/zuf/rw.c new file +2 -0
+
+       return size ?: ret;

It looks like you're returning "ret" if the ternary evaluates to false, but it's not clear to
me what is returned if it evaluates to true. It's possible it's okay, but I just don't know
enough about how ternaries work in this case.

Yes Thanks, Will fix. Not suppose to use this in the Kernel.

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+

<>

Quoted 32 lines
Quoted 19 lines
fs/zuf/rw.c new file +19 -0
+int zuf_iom_execute_sync(struct super_block *sb, struct inode *inode,
+                        __u64 *iom_e_user, uint iom_n)
+{
+       struct zuf_sb_info *sbi = SBI(sb);
+       struct t2_io_state rd_tis = {};
+       struct t2_io_state wr_tis = {};
+       struct _iom_exec_info iei = {};
+       int err, err_r, err_w;
+
+       t2_io_begin(sbi->md, READ, NULL, 0, -1, &rd_tis);
+       t2_io_begin(sbi->md, WRITE, NULL, 0, -1, &wr_tis);
+
+       iei.sb = sb;
+       iei.inode = inode;
+       iei.rd_tis = &rd_tis;
+       iei.wr_tis = &wr_tis;
+       iei.iom_e = iom_e_user;
+       iei.iom_n = iom_n;
+       iei.print = 0;

fs/zuf/rw.c line 951

Quoted 10 lines
fs/zuf/rw.c new file +10 -0
+
+       err = _iom_execute_inline(&iei);
+
+       err_r = t2_io_end(&rd_tis, true);
+       err_w = t2_io_end(&wr_tis, true);
+
+       /* TODO: not sure if OK when _iom_execute return with -ENOMEM
+        * In such a case, we might be better of skiping t2_io_ends.
+        */
+       return err ?: (err_r ?: err_w);

Same question here.

Quoted 8 lines
Quoted 3 lines

Thanks,
Anna

Yes Will fix

Thanks Anna
Can I put Reviewed-by on this patch?

Go for it!

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

+}

Much obliged
Boaz

#17 lore raw

PATCH v2 12/16 zuf: mmap & sync

In reply to Boaz Harrosh

On page-fault call the zusFS for the page information. We always mmap pmem pages directly. (No page cache)

With write-mmap and pmem. We need to keep track of dirty inodes and call the zusFS when one of the sync variants are called. This is because the Server will need to do a cl_flush on all dirty pages.

If we did not have any write-mmaped pages on the inode sync does nothing.

[v2]
zuf: pmem mmap must be 2M aligned

We only support huge pages on pmem mmap (2M). Prevent mmap on pmem with VM addresses unaligned to 2M.

[Under valgrind it would try to give us address not aligned
and bypass the zufr_get_unmapped_area(). By returning an error valgrind backs off and everything works again
]

---
 fs/zuf/Makefile   |   2 +-
 fs/zuf/_extern.h  |   6 +
 fs/zuf/file.c     |  66 ++++++++++
 fs/zuf/inode.c    |  10 ++
 fs/zuf/mmap.c     | 300 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/super.c    |  89 ++++++++++++++
 fs/zuf/t1.c       |   9 ++
 fs/zuf/zuf-core.c |   2 +
 fs/zuf/zuf.h      |   3 +
 fs/zuf/zus_api.h  |  26 ++++
 10 files changed, 512 insertions(+), 1 deletion(-)
 create mode 100644 fs/zuf/mmap.c
fs/zuf/Makefile +1 -1
index 23bc3791a001..02df1374a946 100644
@@ -17,6 +17,6 @@ zuf-y += md.o t1.o t2.o
 zuf-y += zuf-core.o zuf-root.o
 
 # Main FS
-zuf-y += rw.o
+zuf-y += rw.o mmap.o
 zuf-y += super.o inode.o directory.o namei.o file.o symlink.o
 zuf-y += module.o
fs/zuf/_extern.h +6 -0
index 745d0cc9e719..cafda97c973c 100644
@@ -64,8 +64,11 @@ int zuf_private_mount(struct zuf_root_info *zri, struct register_fs_info *rfi,
 int zuf_private_umount(struct zuf_root_info *zri, struct super_block *sb);
 struct super_block *zuf_sb_from_id(struct zuf_root_info *zri, __u64 sb_id,
 				   struct zus_sb_info *zus_sbi);
+void zuf_sync_inc(struct inode *inode);
+void zuf_sync_dec(struct inode *inode, ulong write_unmapped);
 
 /* file.c */
+int zuf_isync(struct inode *inode, loff_t start, loff_t end, int datasync);
 long __zuf_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len);
 
 /* namei.c */
@@ -114,6 +117,9 @@ int zuf_iom_execute_async(struct super_block *sb, struct zus_iomap_build *iomb,
 int zuf_rw_file_range_compare(struct inode *i_in, loff_t pos_in,
 			      struct inode *i_out, loff_t pos_out, loff_t len);
 
+/* mmap.c */
+int zuf_file_mmap(struct file *file, struct vm_area_struct *vma);
+
 /* t1.c */
 int zuf_pmem_mmap(struct file *file, struct vm_area_struct *vma);
 
fs/zuf/file.c +66 -0

78 lines not on this page · raw message

fs/zuf/inode.c +10 -0
index 27660979ed6f..1e3dba654f34 100644
@@ -271,6 +271,7 @@ void zuf_evict_inode(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
 	struct zuf_inode_info *zii = ZUII(inode);
+	int write_mapped;
 
 	if (!inode->i_nlink) {
 		if (unlikely(!zii->zi)) {
@@ -311,6 +312,15 @@ void zuf_evict_inode(struct inode *inode)
 	zii->zus_ii = NULL;
 	zii->zi = NULL;
 
+	/* ZUS on evict has synced all mmap dirty pages, YES? */
+	write_mapped = atomic_read(&zii->write_mapped);
+	if (unlikely(write_mapped || !list_empty(&zii->i_mmap_dirty))) {
+		zuf_dbg_mmap("[%ld] !!!! write_mapped=%d list_empty=%d\n",
+			      inode->i_ino, write_mapped,
+			      list_empty(&zii->i_mmap_dirty));
+		zuf_sync_dec(inode, write_mapped);
+	}
+
 	clear_inode(inode);
 }
 
fs/zuf/mmap.c new file +300 -0

300 lines not on this page · raw message

fs/zuf/super.c +89 -0

108 lines not on this page · raw message

fs/zuf/t1.c +9 -0
index 46ea7f6181fc..1f2db5a674d5 100644
@@ -124,6 +124,15 @@ int zuf_pmem_mmap(struct file *file, struct vm_area_struct *vma)
 	if (!zsf || zsf->type != zlfs_e_pmem)
 		return -EPERM;
 
+	/* Valgrined may interfere with our 2M mmap aligned vma start
+	 * (See zufr_get_unmapped_area). Tell the guys to back off
+	 */
+	if (unlikely(vma->vm_start & ~PMD_MASK)) {
+		zuf_err("mmap is not 2M aligned vm_start=0x%lx\n",
+				vma->vm_start);
+		return -EINVAL;
+	}
+
 	vma->vm_flags |= VM_HUGEPAGE;
 	vma->vm_ops = &t1_vm_ops;
 
fs/zuf/zuf-core.c +2 -0
index 11300fd79929..cb4a4def646f 100644
@@ -99,7 +99,9 @@ const char *zuf_op_name(enum e_zufs_operation op)
 		CASE_ENUM_NAME(ZUFS_OP_READ);
 		CASE_ENUM_NAME(ZUFS_OP_PRE_READ);
 		CASE_ENUM_NAME(ZUFS_OP_WRITE);
+		CASE_ENUM_NAME(ZUFS_OP_MMAP_CLOSE);
 		CASE_ENUM_NAME(ZUFS_OP_SETATTR);
+		CASE_ENUM_NAME(ZUFS_OP_SYNC);
 
 		CASE_ENUM_NAME(ZUFS_OP_GET_MULTY);
 		CASE_ENUM_NAME(ZUFS_OP_PUT_MULTY);
fs/zuf/zuf.h +3 -0
index 2c57c51a2099..fe479cb70f97 100644
@@ -132,6 +132,9 @@ struct zuf_inode_info {
 
 	/* Stuff for mmap write */
 	struct rw_semaphore	in_sync;
+	struct list_head	i_mmap_dirty;
+	atomic_t		write_mapped;
+	atomic_t		vma_count;
 
 	/* cookies from Server */
 	struct zus_inode	*zi;
fs/zuf/zus_api.h +26 -0
index e3a783748ce6..e70bd8b7ff69 100644
@@ -459,7 +459,9 @@ enum e_zufs_operation {
 	ZUFS_OP_READ		= 14,
 	ZUFS_OP_PRE_READ	= 15,
 	ZUFS_OP_WRITE		= 16,
+	ZUFS_OP_MMAP_CLOSE	= 17,
 	ZUFS_OP_SETATTR		= 19,
+	ZUFS_OP_SYNC		= 20,
 	ZUFS_OP_FALLOCATE	= 21,
 
 	ZUFS_OP_GET_MULTY	= 29,
@@ -645,6 +647,13 @@ static inline bool zufs_zde_emit(struct zufs_readdir_iter *rdi, __u64 ino,
 }
 #endif /* ndef __cplusplus */
 
+struct zufs_ioc_mmap_close {
+	struct zufs_ioc_hdr hdr;
+	 /* IN */
+	struct zus_inode_info *zus_ii;
+	__u64 rw; /* Some flags + READ or WRITE */
+};
+
 /* ZUFS_OP_SETATTR */
 struct zufs_ioc_attr {
 	struct zufs_ioc_hdr hdr;
@@ -654,6 +663,23 @@ struct zufs_ioc_attr {
 	__u32 pad;
 };
 
+/* ZUFS_OP_SYNC */
+enum ZUFS_SYNC_FLAGS {
+	ZUFS_SF_DATASYNC		= 0x00000001,
+	ZUFS_SF_DONTNEED		= 0x00000100,
+};
+
+struct zufs_ioc_sync {
+	struct zufs_ioc_hdr hdr;
+	/* IN */
+	struct zus_inode_info *zus_ii;
+	__u64 offset, length;
+	__u64 flags;
+
+	/* OUT */
+	__u64 write_unmapped;
+};
+
 /* ~~~~ io_map structures && IOCTL(s) ~~~~ */
 /*
  * These set of structures and helpers are used in return of zufs_ioc_IO and
Signature · 1 line
2.21.0
#18 lore raw

PATCH v2 13/16 zuf: More file operation

In reply to Boaz Harrosh

Add more file/inode operation:

vector function operation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.llseek zuf_llseek ZUFS_OP_LLSEEK

.fallocate zuf_fallocate ZUFS_OP_FALLOCATE
.copy_file_range zuf_copy_file_range ZUFS_OP_COPY
.remap_file_range zuf_clone_file_range ZUFS_OP_CLONE
.fadvise zuf_fadvise (multiple see rw.c)
.fiemap zuf_fiemap ZUFS_OP_FIEMAP

See more comments in source code.

[v2]
SQUASHME zuf: fadvise fix up missing operations

Mainly there was a bug found by Vlad, that POSIX_FADV_RANDOM was missing and therefor was returning and error and some tests were failing.
But while at it actually implement all the missing advise. Just punch into file->ra the proper flags.
FIXME: There is a pending patch by Jan to export generic_fadvise
for now duplicate what we need inline.

[v3]
zuf: lock two zii fix

[v4]
zuf: Reduce stack usage (fiemap)
Same as for IO use the big_alloc to prevent compilation warning

---
 fs/zuf/_extern.h  |   3 +
 fs/zuf/file.c     | 650 +++++++++++++++++++++++++++++++++++++++++++++-
 fs/zuf/rw.c       |  92 +++++++
 fs/zuf/zuf-core.c |   5 +
 fs/zuf/zus_api.h  |  83 ++++++
 5 files changed, 832 insertions(+), 1 deletion(-)
fs/zuf/_extern.h +3 -0
index cafda97c973c..2c7456724ef6 100644
@@ -110,6 +110,9 @@ int _zufs_IO_get_multy(struct zuf_sb_info *sbi, struct inode *inode,
 void _zufs_IO_put_multy(struct zuf_sb_info *sbi, struct inode *inode,
 			struct _io_gb_multy *io_gb);
 int zuf_rw_fallocate(struct inode *inode, uint mode, loff_t offset, loff_t len);
+int zuf_rw_fadvise(struct super_block *sb, struct file *file,
+		   loff_t offset, loff_t len, int advise, bool rand);
+
 int zuf_iom_execute_sync(struct super_block *sb, struct inode *inode,
 			 __u64 *iom_e, uint iom_n);
 int zuf_iom_execute_async(struct super_block *sb, struct zus_iomap_build *iomb,
fs/zuf/file.c +649 -1

683 lines not on this page · raw message

fs/zuf/rw.c +92 -0

98 lines not on this page · raw message

fs/zuf/zuf-core.c +5 -0
index cb4a4def646f..4284d2298906 100644
@@ -95,6 +95,8 @@ const char *zuf_op_name(enum e_zufs_operation op)
 		CASE_ENUM_NAME(ZUFS_OP_REMOVE_DENTRY);
 		CASE_ENUM_NAME(ZUFS_OP_RENAME);
 		CASE_ENUM_NAME(ZUFS_OP_READDIR);
+		CASE_ENUM_NAME(ZUFS_OP_CLONE);
+		CASE_ENUM_NAME(ZUFS_OP_COPY);
 
 		CASE_ENUM_NAME(ZUFS_OP_READ);
 		CASE_ENUM_NAME(ZUFS_OP_PRE_READ);
@@ -102,6 +104,9 @@ const char *zuf_op_name(enum e_zufs_operation op)
 		CASE_ENUM_NAME(ZUFS_OP_MMAP_CLOSE);
 		CASE_ENUM_NAME(ZUFS_OP_SETATTR);
 		CASE_ENUM_NAME(ZUFS_OP_SYNC);
+		CASE_ENUM_NAME(ZUFS_OP_FALLOCATE);
+		CASE_ENUM_NAME(ZUFS_OP_LLSEEK);
+		CASE_ENUM_NAME(ZUFS_OP_FIEMAP);
 
 		CASE_ENUM_NAME(ZUFS_OP_GET_MULTY);
 		CASE_ENUM_NAME(ZUFS_OP_PUT_MULTY);
fs/zuf/zus_api.h +83 -0

101 lines not on this page · raw message

Signature · 1 line
2.21.0
#19 lore raw

PATCH v2 14/16 zuf: ioctl implementation

In reply to Boaz Harrosh

* support for some generic IOCTLs:
FS_IOC_GETFLAGS, FS_IOC_SETFLAGS, FS_IOC_GETVERSION, FS_IOC_SETVERSION

* Simple support for zusFS defined IOCTLs
We only support flat structures
(no emmbedded pointers within the IOCTL structures) We try to deduce the size of the IOCTL from the _IOC_SIZE(cmd) If zusFS needs a bigger copy it will send a retry with the new size. So bad defined IOCTLs always do 2 trips to userland

* zusFS may also retry if it wants an fs_freeze to implement its IOCTL (TODO keep a map)

[v2]
zuf: Reduce stack usage (ioctl)
Same as for IO use big_alloc for buffers too big for on the stack

---
 fs/zuf/Makefile    |   1 +
 fs/zuf/_extern.h   |   6 +
 fs/zuf/directory.c |   4 +
 fs/zuf/file.c      |   4 +
 fs/zuf/ioctl.c     | 309 +++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf-core.c  |   1 +
 fs/zuf/zus_api.h   |  37 ++++++
 7 files changed, 362 insertions(+)
 create mode 100644 fs/zuf/ioctl.c
fs/zuf/Makefile +1 -0
index 02df1374a946..d3257bfc69ba 100644
@@ -17,6 +17,7 @@ zuf-y += md.o t1.o t2.o
 zuf-y += zuf-core.o zuf-root.o
 
 # Main FS
+zuf-y += ioctl.o
 zuf-y += rw.o mmap.o
 zuf-y += super.o inode.o directory.o namei.o file.o symlink.o
 zuf-y += module.o
fs/zuf/_extern.h +6 -0
index 2c7456724ef6..04e0515469e7 100644
@@ -126,6 +126,12 @@ int zuf_file_mmap(struct file *file, struct vm_area_struct *vma);
 /* t1.c */
 int zuf_pmem_mmap(struct file *file, struct vm_area_struct *vma);
 
+/* ioctl.c */
+long zuf_ioctl(struct file *filp, uint cmd, ulong arg);
+#ifdef CONFIG_COMPAT
+long zuf_compat_ioctl(struct file *file, uint cmd, ulong arg);
+#endif
+
 /*
  * Inode and files operations
  */
fs/zuf/directory.c +4 -0
index 7417aeb77773..612b6e410615 100644
@@ -164,4 +164,8 @@ const struct file_operations zuf_dir_operations = {
 	.read		= generic_read_dir,
 	.iterate_shared	= zuf_readdir,
 	.fsync		= noop_fsync,
+	.unlocked_ioctl = zuf_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl	= zuf_compat_ioctl,
+#endif
 };
fs/zuf/file.c +4 -0
index 1c51529694e7..e0bd60e095e7 100644
@@ -808,6 +808,10 @@ const struct file_operations zuf_file_operations = {
 	.copy_file_range	= zuf_copy_file_range,
 	.remap_file_range	= zuf_clone_file_range,
 	.fadvise		= zuf_fadvise,
+	.unlocked_ioctl		= zuf_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl		= zuf_compat_ioctl,
+#endif
 };
 
 const struct inode_operations zuf_file_inode_operations = {
fs/zuf/ioctl.c new file +309 -0

309 lines not on this page · raw message

fs/zuf/zuf-core.c +1 -0
index 4284d2298906..9b8fe3bff0cd 100644
@@ -106,6 +106,7 @@ const char *zuf_op_name(enum e_zufs_operation op)
 		CASE_ENUM_NAME(ZUFS_OP_SYNC);
 		CASE_ENUM_NAME(ZUFS_OP_FALLOCATE);
 		CASE_ENUM_NAME(ZUFS_OP_LLSEEK);
+		CASE_ENUM_NAME(ZUFS_OP_IOCTL);
 		CASE_ENUM_NAME(ZUFS_OP_FIEMAP);
 
 		CASE_ENUM_NAME(ZUFS_OP_GET_MULTY);
fs/zuf/zus_api.h +37 -0
index c8bcb6006fab..4ebb067c0719 100644
@@ -466,6 +466,7 @@ enum e_zufs_operation {
 	ZUFS_OP_SYNC		= 20,
 	ZUFS_OP_FALLOCATE	= 21,
 	ZUFS_OP_LLSEEK		= 22,
+	ZUFS_OP_IOCTL		= 23,
 	ZUFS_OP_FIEMAP		= 28,
 
 	ZUFS_OP_GET_MULTY	= 29,
@@ -708,6 +709,42 @@ struct zufs_ioc_seek {
 	__u64 offset_out;
 };
 
+/* ZUFS_OP_IOCTL */
+/* Flags for zufs_ioc_ioctl->kflags */
+enum e_ZUFS_IOCTL_KFLAGS {
+	ZUFS_IOC_FSFROZEN	= 0x1,	/* Tell Server we froze the FS	  */
+	ZUFS_IOC_CAP_ADMIN	= 0x2,	/* The ioctl caller had CAP_ADMIN */
+};
+
+/* received for zus on zufs_ioc_ioctl->uflags */
+enum e_ZUFS_IOCTL_UFLAGS {
+	ZUFS_IOC_REALLOC	= 0x1,	/*_IOC_SIZE(cmd) was not it and Server
+					 * needs a deeper copy
+					 */
+	ZUFS_IOC_FREEZE_REQ	= 0x2,	/* Server needs a freeze and a recall */
+};
+
+struct zufs_ioc_ioctl {
+	struct zufs_ioc_hdr hdr;
+	/* IN */
+	struct zus_inode_info *zus_ii;
+	__u64 time;
+	__u32 cmd;
+	__u32 kflags; /* zuf/kernel state and flags*/
+
+	/* OUT */
+	/* This is just a zero-size marker for the start of output */
+	char out_start[0];
+	union {
+		struct { /* If return was -EZUFS_RETRY */
+			__u32 uflags; /* flags returned from zus */
+			__u32 new_size;
+		};
+
+		char arg[0];
+	};
+};
+
 /* ZUFS_OP_FIEMAP */
 struct zufs_ioc_fiemap {
 	struct zufs_ioc_hdr hdr;
Signature · 1 line
2.21.0
#20 lore raw

PATCH v2 15/16 zuf: xattr && acl implementation

In reply to Boaz Harrosh

We establish the usual dispatch API to user-mode, for get/set/list_xattr.
Since the buffers are variable length we utilize the zdo->overflow_handler for the extra copy from Server. (see also zuf-core.c)

The ACL support is all in Kernel. There is no new API with zusFS.
We define the internal structure of the ACL inside an opec xattr and store via the xattr zus_api.

TODO:
Future FSs that have their own ACL on-disk-format, and/or Network zusFS that have their own verifiers for the ACL will need to establish an alternative API for the acl.

---
 fs/zuf/Makefile   |   2 +-
 fs/zuf/_extern.h  |  20 +++
 fs/zuf/acl.c      | 270 +++++++++++++++++++++++++++++++++++++++
 fs/zuf/file.c     |   3 +
 fs/zuf/inode.c    |  18 +++
 fs/zuf/namei.c    |   6 +
 fs/zuf/super.c    |   2 +
 fs/zuf/symlink.c  |   1 +
 fs/zuf/xattr.c    | 314 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf-core.c |   3 +
 fs/zuf/zuf.h      |  34 +++++
 fs/zuf/zus_api.h  |  25 +++-
 12 files changed, 696 insertions(+), 2 deletions(-)
 create mode 100644 fs/zuf/acl.c
 create mode 100644 fs/zuf/xattr.c
fs/zuf/Makefile +1 -1
index d3257bfc69ba..abc7dcda0029 100644
@@ -17,7 +17,7 @@ zuf-y += md.o t1.o t2.o
 zuf-y += zuf-core.o zuf-root.o
 
 # Main FS
-zuf-y += ioctl.o
+zuf-y += ioctl.o acl.o xattr.o
 zuf-y += rw.o mmap.o
 zuf-y += super.o inode.o directory.o namei.o file.o symlink.o
 zuf-y += module.o
fs/zuf/_extern.h +20 -0
index 04e0515469e7..d0d83eae75c1 100644
@@ -132,6 +132,26 @@ long zuf_ioctl(struct file *filp, uint cmd, ulong arg);
 long zuf_compat_ioctl(struct file *file, uint cmd, ulong arg);
 #endif
 
+/* xattr.c */
+int zuf_initxattrs(struct inode *inode, const struct xattr *xattr_array,
+		   void *fs_info);
+ssize_t __zuf_getxattr(struct inode *inode, int type, const char *name,
+		       void *buffer, size_t size);
+int __zuf_setxattr(struct inode *inode, int type, const char *name,
+		   const void *value, size_t size, int flags);
+ssize_t zuf_listxattr(struct dentry *dentry, char *buffer, size_t size);
+extern const struct xattr_handler *zuf_xattr_handlers[];
+
+/* acl.c */
+int zuf_set_acl(struct inode *inode, struct posix_acl *acl, int type);
+struct posix_acl *zuf_get_acl(struct inode *inode, int type);
+int zuf_acls_create_pre(struct inode *dir, umode_t *mode,
+			struct posix_acl **def_acl, struct posix_acl **acl);
+int zuf_acls_create_post(struct inode *dir, struct inode *inode,
+			 struct posix_acl *def_acl, struct posix_acl *acl);
+extern const struct xattr_handler zuf_acl_access_xattr_handler;
+extern const struct xattr_handler zuf_acl_default_xattr_handler;
+
 /*
  * Inode and files operations
  */
fs/zuf/acl.c new file +270 -0

270 lines not on this page · raw message

fs/zuf/file.c +3 -0
index e0bd60e095e7..a4a788dcdc87 100644
@@ -819,4 +819,7 @@ const struct inode_operations zuf_file_inode_operations = {
 	.getattr	= zuf_getattr,
 	.update_time	= zuf_update_time,
 	.fiemap		= zuf_fiemap,
+	.get_acl	= zuf_get_acl,
+	.set_acl	= zuf_set_acl,
+	.listxattr	= zuf_listxattr,
 };
fs/zuf/inode.c +18 -0
index 1e3dba654f34..ed324701a20b 100644
@@ -287,6 +287,7 @@ void zuf_evict_inode(struct inode *inode)
 			_warn_inode_dirty(inode, zii->zi);
 
 		zuf_w_lock(zii);
+		zuf_xaw_lock(zii); /* Needed? probably not but palying safe */
 
 		zufc_goose_all_zts(ZUF_ROOT(SBI(sb)), inode);
 
@@ -295,6 +296,7 @@ void zuf_evict_inode(struct inode *inode)
 		inode->i_mtime = inode->i_ctime = current_time(inode);
 		inode->i_size = 0;
 
+		zuf_xaw_unlock(zii);
 		zuf_w_unlock(zii);
 	} else {
 		zuf_dbg_vfs("[%ld] inode is going down?\n", inode->i_ino);
@@ -341,6 +343,7 @@ struct inode *zuf_new_inode(struct inode *dir, umode_t mode,
 		.flags = tmpfile ? ZI_TMPFILE : 0,
 		.str.len = qstr->len,
 	};
+	struct posix_acl *acl = NULL, *def_acl = NULL;
 	struct inode *inode;
 	struct zus_inode *zi = NULL;
 	struct page *pages[2];
@@ -360,6 +363,15 @@ struct inode *zuf_new_inode(struct inode *dir, umode_t mode,
 
 	zuf_dbg_verbose("inode=%p name=%s\n", inode, qstr->name);
 
+	err = security_inode_init_security(inode, dir, qstr, zuf_initxattrs,
+					   NULL);
+	if (err && err != -EOPNOTSUPP)
+		goto fail;
+
+	err = zuf_acls_create_pre(dir, &inode->i_mode, &def_acl, &acl);
+	if (unlikely(err))
+		goto fail;
+
 	zuf_set_inode_flags(inode, &ioc_new_inode.zi);
 
 	if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
@@ -400,6 +412,12 @@ struct inode *zuf_new_inode(struct inode *dir, umode_t mode,
 
 	zuf_dbg_verbose("allocating inode %ld (zi=%p)\n", _zi_ino(zi), zi);
 
+	if ((def_acl || acl) && !symname) {
+		err = zuf_acls_create_post(dir, inode, def_acl, acl);
+		if (unlikely(err))
+			goto fail;
+	}
+
 	err = insert_inode_locked(inode);
 	if (unlikely(err)) {
 		zuf_dbg_err("[%ld:%s] generation=%lld insert_inode_locked => %d\n",
fs/zuf/namei.c +6 -0
index e78aa04f10d5..a33745c328b9 100644
@@ -420,10 +420,16 @@ const struct inode_operations zuf_dir_inode_operations = {
 	.setattr	= zuf_setattr,
 	.getattr	= zuf_getattr,
 	.update_time	= zuf_update_time,
+	.get_acl	= zuf_get_acl,
+	.set_acl	= zuf_set_acl,
+	.listxattr	= zuf_listxattr,
 };
 
 const struct inode_operations zuf_special_inode_operations = {
 	.setattr	= zuf_setattr,
 	.getattr	= zuf_getattr,
 	.update_time	= zuf_update_time,
+	.get_acl	= zuf_get_acl,
+	.set_acl	= zuf_set_acl,
+	.listxattr	= zuf_listxattr,
 };
fs/zuf/super.c +2 -0
index 2a0db11b51d6..8f760e8b3fdc 100644
@@ -553,6 +553,7 @@ static int zuf_fill_super(struct super_block *sb, void *data, int silent)
 		sb->s_flags |= SB_POSIXACL;
 
 	sb->s_op = &zuf_sops;
+	sb->s_xattr = zuf_xattr_handlers;
 
 	root_i = zuf_iget(sb, ioc_mount->zmi.zus_ii, ioc_mount->zmi._zi,
 			  &exist);
@@ -845,6 +846,7 @@ static void _init_once(void *foo)
 	inode_init_once(&zii->vfs_inode);
 	INIT_LIST_HEAD(&zii->i_mmap_dirty);
 	zii->zi = NULL;
+	init_rwsem(&zii->xa_rwsem);
 	init_rwsem(&zii->in_sync);
 	atomic_set(&zii->vma_count, 0);
 	atomic_set(&zii->write_mapped, 0);
fs/zuf/symlink.c +1 -0
index 1446bdf60cb9..5e9115ba4cbd 100644
@@ -70,4 +70,5 @@ const struct inode_operations zuf_symlink_inode_operations = {
 	.update_time	= zuf_update_time,
 	.setattr	= zuf_setattr,
 	.getattr	= zuf_getattr,
+	.listxattr	= zuf_listxattr,
 };
fs/zuf/xattr.c new file +314 -0

314 lines not on this page · raw message

fs/zuf/zuf-core.c +3 -0
index 9b8fe3bff0cd..d3252ca7d2d1 100644
@@ -107,6 +107,9 @@ const char *zuf_op_name(enum e_zufs_operation op)
 		CASE_ENUM_NAME(ZUFS_OP_FALLOCATE);
 		CASE_ENUM_NAME(ZUFS_OP_LLSEEK);
 		CASE_ENUM_NAME(ZUFS_OP_IOCTL);
+		CASE_ENUM_NAME(ZUFS_OP_XATTR_GET);
+		CASE_ENUM_NAME(ZUFS_OP_XATTR_SET);
+		CASE_ENUM_NAME(ZUFS_OP_XATTR_LIST);
 		CASE_ENUM_NAME(ZUFS_OP_FIEMAP);
 
 		CASE_ENUM_NAME(ZUFS_OP_GET_MULTY);
fs/zuf/zuf.h +34 -0
index fe479cb70f97..4a1d474eb80b 100644
@@ -130,6 +130,8 @@ enum {
 struct zuf_inode_info {
 	struct inode		vfs_inode;
 
+	/* Lock for xattr operations */
+	struct rw_semaphore	xa_rwsem;
 	/* Stuff for mmap write */
 	struct rw_semaphore	in_sync;
 	struct list_head	i_mmap_dirty;
@@ -313,6 +315,38 @@ static inline void ZUF_CHECK_I_W_LOCK(struct inode *inode)
 		up_write(&inode->i_rwsem);
 #endif
 }
+static inline void zuf_xar_lock(struct zuf_inode_info *zii)
+{
+	down_read(&zii->xa_rwsem);
+}
+
+static inline void zuf_xar_unlock(struct zuf_inode_info *zii)
+{
+	up_read(&zii->xa_rwsem);
+}
+
+static inline void zuf_xaw_lock(struct zuf_inode_info *zii)
+{
+	down_write(&zii->xa_rwsem);
+}
+
+static inline void zuf_xaw_unlock(struct zuf_inode_info *zii)
+{
+	up_write(&zii->xa_rwsem);
+}
+
+/* xattr types */
+enum {	ZUF_XF_SECURITY    = 1,
+	ZUF_XF_SYSTEM      = 2,
+	ZUF_XF_TRUSTED     = 3,
+	ZUF_XF_USER        = 4,
+};
+
+struct zuf_acl {
+	__le16	tag;
+	__le16	perm;
+	__le32	id;
+};
 
 enum big_alloc_type { ba_stack, ba_8k, ba_vmalloc };
 #define S_8K (1024UL * 8)
fs/zuf/zus_api.h +24 -1
index 4ebb067c0719..1359f0384f82 100644
@@ -467,6 +467,9 @@ enum e_zufs_operation {
 	ZUFS_OP_FALLOCATE	= 21,
 	ZUFS_OP_LLSEEK		= 22,
 	ZUFS_OP_IOCTL		= 23,
+	ZUFS_OP_XATTR_GET	= 24,
+	ZUFS_OP_XATTR_SET	= 25,
+	ZUFS_OP_XATTR_LIST	= 27,
 	ZUFS_OP_FIEMAP		= 28,
 
 	ZUFS_OP_GET_MULTY	= 29,
@@ -745,6 +748,26 @@ struct zufs_ioc_ioctl {
 	};
 };
 
+/* ZUFS_OP_XATTR */
+/* xattr ioc_flags */
+#define ZUFS_XATTR_SET_EMPTY	(1 << 0)
+#define ZUFS_XATTR_TRUSTED	(1 << 1)
+
+struct zufs_ioc_xattr {
+	struct zufs_ioc_hdr hdr;
+	/* IN */
+	struct zus_inode_info *zus_ii;
+	__u32	flags;
+	__u32	type;
+	__u16	name_len;
+	__u16	ioc_flags;
+
+	/* OUT */
+	__u32	user_buf_size;
+	char	buf[0];
+};
+
+
 /* ZUFS_OP_FIEMAP */
 struct zufs_ioc_fiemap {
 	struct zufs_ioc_hdr hdr;
@@ -760,7 +783,7 @@ struct zufs_ioc_fiemap {
 	__u32	extents_mapped;
 	__u32	pad;
 
-} __packed;
+};
 
 struct zufs_fiemap_extent_info {
 	struct fiemap_extent *fi_extents_start;
Signature · 1 line
2.21.0
#21 lore raw

PATCH v2 16/16 zuf: Support for dynamic-debug of zusFSs

In reply to Boaz Harrosh

[THIS PATCH will be changed or dropped before final submission]

In zus we support dynamic-debug prints. ie user can turn on and off the prints at run time by writing to some special files.

The API is exactly the same as the Kernel's dynamic-prints only the special file that we perform read/write on is:
/sys/fs/zuf/ddbg

But otherwise it is identical to Kernel.

The Kernel code is a thin wrapper to dispatch to/from the read/write of /sys/fs/zuf/ddbg file to the zus server.
The heavy lifting is done by the zus project build system and core code. See zus project how this is done

This facility is dispatched on the mount-thread and not the regular ZTs. Because it is available globally before any mounts.

---
 fs/zuf/_extern.h  |  3 ++
 fs/zuf/zuf-root.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)
fs/zuf/_extern.h +3 -0
index d0d83eae75c1..40cc228e4c99 100644
@@ -29,6 +29,9 @@ int zufc_release(struct inode *inode, struct file *file);
 int zufc_mmap(struct file *file, struct vm_area_struct *vma);
 const char *zuf_op_name(enum e_zufs_operation op);
 
+int __zufc_dispatch_mount(struct zuf_root_info *zri,
+			  enum e_mount_operation op,
+			  struct zufs_ioc_mount *zim);
 int zufc_dispatch_mount(struct zuf_root_info *zri, struct zus_fs_info *zus_zfi,
 			enum e_mount_operation operation,
 			struct zufs_ioc_mount *zim);
fs/zuf/zuf-root.c +76 -0

88 lines not on this page · raw message

Signature · 1 line
2.21.0
#22 lore raw
In reply to Boaz Harrosh
Quoted 20 lines · Boaz Harrosh

Performance:
A simple fio direct 4k random write test with incrementing number of threads.

[fuse]

threads wr_iops wr_bw   wr_lat
1       33606   134424  26.53226
2       57056   228224  30.38476
4       88667   354668  40.12783
7       116561  466245  53.98572
8       129134  516539  55.6134

[fuse-splice]

threads wr_iops wr_bw   wr_lat
1       39670   158682  21.8399
2       51100   204400  34.63294
4       75220   300882  47.42344
7       97706   390825  63.04435
8       98034   392137  73.24263
Quoted 2 lines

[xfs-dax]
threads wr_iops wr_bw wr_lat

Data missing.

Quoted 7 lines

[Maxdata-1.5-zufs]

threads wr_iops wr_bw           wr_lat
1       1041802 260,450         3.623
2       1983997 495,999         3.808
4       3829456 957,364         3.959
7       4501154 1,125,288       5.895330
8       4400698 1,100,174       6.922174

Just a heads up, that I have achieved similar results with a prototype using the unmodified fuse protocol. This prototype was built with ideas taken from zufs (percpu/lockless, mmaped dev, single syscall per op). I found a big scheduler scalability bottleneck that is caused by
update of mm->cpu_bitmap at context switch. This can be worked
around by using shared memory instead of shared page tables, which is a bit of a pain, but it does prove the point. Thought about fixing the cpu_bitmap cacheline pingpong, but didn't really get anywhere.

Are you interested in comparing zufs with the scalable fuse prototype?
If so, I'll push the code into a public repo with some instructions,

Thanks,
Miklos

#23 lore raw

Hi Miklos,

Quoted 11 lines

Just a heads up, that I have achieved similar results with a prototype using the unmodified fuse protocol. This prototype was built with ideas taken from zufs (percpu/lockless, mmaped dev, single syscall per op). I found a big scheduler scalability bottleneck that is caused by
update of mm->cpu_bitmap at context switch. This can be worked
around by using shared memory instead of shared page tables, which is a bit of a pain, but it does prove the point. Thought about fixing the cpu_bitmap cacheline pingpong, but didn't really get anywhere.

Are you interested in comparing zufs with the scalable fuse prototype?
If so, I'll push the code into a public repo with some instructions,

I would be happy to help here (review, lightly test and debug). I wanted to give the ioctl threads method a try for some time already just never came to it yet.

Thanks,
Bernd

#24 lore raw
In reply to Miklos Szeredi
Quoted 2 lines · Miklos Szeredi

On Thu, Sep 26, 2019 at 4:08 AM Boaz Harrosh <[email protected]> wrote:

<>

Quoted 5 lines
Quoted 2 lines

[xfs-dax]
threads wr_iops wr_bw wr_lat

Data missing.

Ooops sorry will send today

Quoted 17 lines
Quoted 7 lines

[Maxdata-1.5-zufs]

threads wr_iops wr_bw           wr_lat
1       1041802 260,450         3.623
2       1983997 495,999         3.808
4       3829456 957,364         3.959
7       4501154 1,125,288       5.895330
8       4400698 1,100,174       6.922174

Just a heads up, that I have achieved similar results with a prototype using the unmodified fuse protocol. This prototype was built with ideas taken from zufs (percpu/lockless, mmaped dev, single syscall per op). I found a big scheduler scalability bottleneck that is caused by
update of mm->cpu_bitmap at context switch. This can be worked
around by using shared memory instead of shared page tables, which is a bit of a pain, but it does prove the point. Thought about fixing the cpu_bitmap cacheline pingpong, but didn't really get anywhere.

Quoted 3 lines

Are you interested in comparing zufs with the scalable fuse prototype?
If so, I'll push the code into a public repo with some instructions,

Yes please do send it. I will give it a good run.
What fuseFS do you use in usermode?

Quoted 3 lines

Thanks,
Miklos

Thank you Miklos for looking
Boaz

#25 lore raw
Quoted 6 lines
Quoted 3 lines

Are you interested in comparing zufs with the scalable fuse prototype?
If so, I'll push the code into a public repo with some instructions,

Yes please do send it. I will give it a good run.
What fuseFS do you use in usermode?

For the start passthrough should do, modified to skip all data. That is what I am doing to measure fuse bandwidth. It also shouldn't be too difficult to add an in-mem tree for dentries and inodes, to be able to measure without tmpfs overhead.

Bernd

#26 lore raw
Quoted 8 lines · Bernd Schubert
Quoted 6 lines
Quoted 3 lines

Are you interested in comparing zufs with the scalable fuse prototype?
If so, I'll push the code into a public repo with some instructions,

Yes please do send it. I will give it a good run.
What fuseFS do you use in usermode?

For the start passthrough should do, modified to skip all data.

skip all data is not good for me. Because it hides away the page-faults and the actual memory bandwith. But what I do is either memcpy a single preallocated block to all blocks in the IO and/or set in a defined pattern where each ulong in the file contains its offset as data. This gives me true results.

Quoted 5 lines

That is
what I am doing to measure fuse bandwidth. It also shouldn't be too difficult to add an in-mem tree for dentries and inodes, to be able to measure without tmpfs overhead.

Thanks that is very helpful I will use this
Boaz

Quoted 3 lines

Bernd

#27 lore raw
Quoted 7 lines · Boaz Harrosh
Quoted 5 lines · Bernd Schubert
Quoted 5 lines
Quoted 3 lines

Are you interested in comparing zufs with the scalable fuse prototype?
If so, I'll push the code into a public repo with some instructions,

Yes please do send it. I will give it a good run.

git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git#fuse2

Enable:

CONFIG_FUSE2_FS=y
CONFIG_SAMPLE_FUSE2=y

Quoted 1 line
Quoted 1 line
Quoted 1 line

What fuseFS do you use in usermode?

It's the example loopback filesystem supplied in the git tree above. I haven't converted libfuse yet to use the new features, so for now this is the only way to try it.

Usage:

linux/samples/fuse2/loraw -2 -p -t ~/mnt/fuse/

options:

-d: debug
-s: single threaded
-b: FUSE_DEV_IOC_CLONE (v1)
-p: use ioctl for device I/O (v2)
-m: use "map read" transferring offset into file instead of actual data -1: use regular fuse
-2: use experimental fuse2
-t: use shared memory instead of threads

I tested with shmfs, and IIRC got about 4-8us latency, depending on the hardware, type of operation, etc...

Let me know if something's not working properly (this is experimental code).

Thanks,
Miklos

#28 lore raw
In reply to Miklos Szeredi
Quoted 7 lines · Miklos Szeredi

On Thu, Sep 26, 2019 at 4:08 AM Boaz Harrosh <[email protected]> wrote:

Just a heads up, that I have achieved similar results with a prototype using the unmodified fuse protocol. This prototype was built with ideas taken from zufs (percpu/lockless, mmaped dev, single syscall per op).

Quoted 6 lines

I found a big scheduler scalability bottleneck that is caused by
update of mm->cpu_bitmap at context switch. This can be worked
around by using shared memory instead of shared page tables, which is a bit of a pain, but it does prove the point. Thought about fixing the cpu_bitmap cacheline pingpong, but didn't really get anywhere.

I'm not sure what is the scalability bottleneck you are seeing above. With zufs I have a very good scalability, almost flat up to the number of CPUs, and/or the limit of the memory bandwith if I'm accessing pmem.

I do have a bad scalability bottleneck if I use mmap of pages caused by the call to zap_vma_ptes. Which is why I invented the NIO way. (Inspired by you)

Once you send me the git URL I will have a look in the code and see if I can find any differences.

That said I do believe that a new Scheduler object that completely bypasses the scheduler and just relinquishes its time slice to the switched to thread, will cut off another 0.5u from the single thread latency. (5th patch talks about that)

Quoted 6 lines

Are you interested in comparing zufs with the scalable fuse prototype?
If so, I'll push the code into a public repo with some instructions,

Thanks,
Miklos

Miklos would you please have some bandwith to review my code? it would make me very happy and calm. Your input is very valuable to me.

Thanks
Boaz

#29 lore raw
Quoted 10 lines · Boaz Harrosh
Quoted 6 lines · Miklos Szeredi

I found a big scheduler scalability bottleneck that is caused by
update of mm->cpu_bitmap at context switch. This can be worked
around by using shared memory instead of shared page tables, which is a bit of a pain, but it does prove the point. Thought about fixing the cpu_bitmap cacheline pingpong, but didn't really get anywhere.

Quoted 4 lines

I'm not sure what is the scalability bottleneck you are seeing above. With zufs I have a very good scalability, almost flat up to the number of CPUs, and/or the limit of the memory bandwith if I'm accessing pmem.

This was *really* noticable with NUMA and many cpus (>64).

Quoted 2 lines

Miklos would you please have some bandwith to review my code? it would make me very happy and calm. Your input is very valuable to me.

Sure, will look at the patches.

Thanks,
Miklos

#30 lore raw
In reply to Boaz Harrosh
Quoted 4 lines · Matt Benjamin

per discussion 2 weeks ago--is there a git repo or something that I can clone?

Matt

Please look in the cover letter there is a git tree address to clone here:

[v02]
The patches submitted are at:
git https://github.com/NetApp/zufs-zuf upstream-v02

Also the same for zus Server in user-mode + infra:
git https://github.com/NetApp/zufs-zus upstream

Please look in the 3rd patch:
[PATCH 03/16] zuf: Preliminary Documentation

There are instructions what to clone how to compile and install and how to use the scripts in do-zu to run a system.
I would love a good review for this documentation as well I'm sure its wrong and missing. I use it for so long I'm already blind to it.

Please bug me day and night with any question

Thanks
Boaz