Skip to contentSkip to conversation

zuf: ZUFS Zero-copy User-mode FileSystem

PATCH In review Boaz Harrosh 3 participants 27 messages Aug 12, 2019 – Aug 13, 2019 1 message not in the archive

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

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.

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

ZUFS - stands for Zero-copy User-mode FS
The Intention of this project was 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 1.5.
So it is very stable and performant

In the git repository above there is also a backport for rhel 7.6 and 7.7 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)))

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 operations
zuf: ioctl implementation
zuf: xattr && acl implementation
zuf: Support for dynamic-debug of zusFSs

 Documentation/filesystems/zufs.txt |  370 +++++++++++++++++++++++++++++
 MAINTAINERS                        |    6 +
 fs/Kconfig                         |    1 +
 fs/Makefile                        |    1 +
 fs/zuf/Kconfig                     |   24 ++
 fs/zuf/Makefile                    |   23 ++
 fs/zuf/_extern.h                   |  180 ++++++++++++++
 fs/zuf/_pr.h                       |   63 +++++
 fs/zuf/acl.c                       |  270 +++++++++++++++++++++
 fs/zuf/directory.c                 |  167 +++++++++++++
 fs/zuf/file.c                      |  840 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/inode.c                     |  693 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/ioctl.c                     |  313 +++++++++++++++++++++++++
 fs/zuf/md.c                        |  752 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/md.h                        |  332 ++++++++++++++++++++++++++
 fs/zuf/md_def.h                    |  145 ++++++++++++
 fs/zuf/mmap.c                      |  300 ++++++++++++++++++++++++
 fs/zuf/module.c                    |   28 +++
 fs/zuf/namei.c                     |  435 ++++++++++++++++++++++++++++++++++
 fs/zuf/relay.h                     |  104 +++++++++
 fs/zuf/rw.c                        |  977 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/super.c                     |  925 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/symlink.c                   |   74 ++++++
 fs/zuf/t1.c                        |  135 +++++++++++
 fs/zuf/t2.c                        |  356 ++++++++++++++++++++++++++++
 fs/zuf/t2.h                        |   68 ++++++
 fs/zuf/xattr.c                     |  314 +++++++++++++++++++++++++
 fs/zuf/zuf-core.c                  | 1716 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf-root.c                  |  520 +++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf.h                       |  437 ++++++++++++++++++++++++++++++++++
 fs/zuf/zus_api.h                   | 1079 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 31 files changed, 11648 insertions(+)
#1 lore raw

PATCH 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 | 100 +++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 168 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 c9aea23aba56..b007c542de45 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 +100 -0

100 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

PATCH 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 677ef41cb012..5ecd89ea256f 100644
@@ -17542,6 +17542,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.20.1
#3 lore raw

PATCH 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.20.1
#4 lore raw

PATCH 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 | 435 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf.h      | 115 ++++++++++++
 fs/zuf/zus_api.h  |  36 ++++
 8 files changed, 816 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 +435 -0

435 lines not on this page · raw message

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

115 lines not on this page · raw message

fs/zuf/zus_api.h +36 -0
index 4b1816e5dfd8..181805052ec0 100644
@@ -97,4 +97,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.20.1
#5 lore raw

PATCH 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 the the next thread. Maybe we can cut another 1/2 a micro off the latency of an IOP (By avoiding locks and atomics)

---
 fs/zuf/_extern.h  |   16 +
 fs/zuf/relay.h    |  104 +++++
 fs/zuf/zuf-core.c | 1064 ++++++++++++++++++++++++++++++++++++++++++++-
 fs/zuf/zuf.h      |   41 ++
 fs/zuf/zus_api.h  |  291 +++++++++++++
 5 files changed, 1515 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/relay.h new file +104 -0

104 lines not on this page · raw message

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

1,103 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.20.1
#6 lore raw

Re: [PATCH 05/16] zuf: zuf-core The ZTs

I love your patch! Yet something to improve:

Hi Boaz,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

fs/zuf/zuf-core.c: In function '_r_zufs_dispatch':

>> fs/zuf/zuf-core.c:697:46: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'mems_allowed'?
     cpumask_copy(&zt->relay.cpus_allowed, &app->cpus_allowed);
                                                 ^~~~~~~~~~~~
                                                 mems_allowed
   fs/zuf/zuf-core.c:698:21: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'mems_allowed'?
     cpumask_copy(&app->cpus_allowed,  cpumask_of(smp_processor_id()));
                        ^~~~~~~~~~~~
                        mems_allowed
   fs/zuf/zuf-core.c:721:22: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'mems_allowed'?
      cpumask_copy(&app->cpus_allowed, &zt->relay.cpus_allowed);
                         ^~~~~~~~~~~~
                         mems_allowed

vim +697 fs/zuf/zuf-core.c

643
644 int __zufc_dispatch(struct zuf_root_info *zri, struct zuf_dispatch_op *zdo)
645 #endif /* CONFIG_ZUF_DEBUG */
646 {
647 struct task_struct *app = get_current();
648 struct zufs_ioc_hdr *hdr = zdo->hdr;
649 int cpu;
650 struct zufc_thread *zt;
651
652 if (unlikely(hdr->out_len && !hdr->out_max)) {
653 /* TODO: Complain here and let caller code do this proper */
654 hdr->out_max = hdr->out_len;
655 }
656
657 if (unlikely(zdo->__locked_zt)) {
658 zt = zdo->__locked_zt;
659 zdo->__locked_zt = NULL;
660
661 cpu = get_cpu();
662 /* FIXME: Very Pedantic need it stay */
663 if (unlikely((zt->zdo != zdo) || cpu != zt->no)) {
664 zuf_warn("[%ld] __locked_zt but zdo(%p != %p) || cpu(%d != %d)\n",
665 _zt_pr_no(zt), zt->zdo, zdo, cpu, zt->no);
666 put_cpu();
667 goto channel_busy;
668 }
669 goto has_channel;
670 }
671 channel_busy:
672 cpu = get_cpu();
673
674 if (!_try_grab_zt_channel(zri, cpu, &zt)) {
675 put_cpu();
676
677 /* If channel was grabbed then maybe a break_all is in progress
678 * on a different CPU make sure zt->file on this core is
679 * updated
680 */
681 mb();
682 if (unlikely(!zt->hdr.file)) {
683 zuf_err("[%d] !zt->file\n", cpu);
684 return -EIO;
685 }
686 zuf_dbg_err("[%d] can this be\n", cpu);
687 /* FIXME: Do something much smarter */
688 msleep(10);
689 if (signal_pending(get_current())) {
690 zuf_dbg_err("[%d] => EINTR\n", cpu);
691 return -EINTR;
692 }
693 goto channel_busy;
694 }
695
696 /* lock app to this cpu while waiting */

 > 697		cpumask_copy(&zt->relay.cpus_allowed, &app->cpus_allowed);

698 cpumask_copy(&app->cpus_allowed, cpumask_of(smp_processor_id()));
699
700 zt->zdo = zdo;
701
702 has_channel:
703 if (zdo->dh)
704 zdo->dh(zdo, zt, zt->opt_buff);
705 else
706 memcpy(zt->opt_buff, zt->zdo->hdr, zt->zdo->hdr->in_len);
707
708 put_cpu();
709
710 if (relay_fss_wakeup_app_wait(&zt->relay) == -ERESTARTSYS) {
711 struct zufs_ioc_hdr *opt_hdr = zt->opt_buff;
712
713 opt_hdr->flags |= ZUFS_H_INTR;
714
715 relay_fss_wakeup_app_wait_cont(&zt->relay);
716 }
717
718 /* __locked_zt must be kept on same cpu */
719 if (!zdo->__locked_zt)
720 /* restore cpu affinity after wakeup */
721 cpumask_copy(&app->cpus_allowed, &zt->relay.cpus_allowed);
722
723 DEBUG_CPU_SWITCH(cpu);
724
725 return zt->hdr.file ? hdr->err : -EIO;
726 }
727

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#7 lore raw

Re: [PATCH 05/16] zuf: zuf-core The ZTs

Quoted 22 lines · kbuild test robot

Hi Boaz,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

fs/zuf/zuf-core.c: In function '_r_zufs_dispatch':

Quoted 1 line
Quoted 1 line

fs/zuf/zuf-core.c:697:46: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'mems_allowed'?

Quoted 11 lines
     cpumask_copy(&zt->relay.cpus_allowed, &app->cpus_allowed);
                                                 ^~~~~~~~~~~~
                                                 mems_allowed
   fs/zuf/zuf-core.c:698:21: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'mems_allowed'?
     cpumask_copy(&app->cpus_allowed,  cpumask_of(smp_processor_id()));
                        ^~~~~~~~~~~~
                        mems_allowed
   fs/zuf/zuf-core.c:721:22: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'mems_allowed'?
      cpumask_copy(&app->cpus_allowed, &zt->relay.cpus_allowed);
                         ^~~~~~~~~~~~
                         mems_allowed

Thank you.

This code is based on v5.2. I guess something changed since 5.3-rc(s) I will try to merge v5.3-rc4 and see how to fix this issue. [I will send a SQUASHME patch on top of the original patch]

Would you prefer to add my github tree to the build or you will apply the fixup patches onto?

Thank you for the report
Boaz

Quoted 93 lines

vim +697 fs/zuf/zuf-core.c

   643	
   644	int __zufc_dispatch(struct zuf_root_info *zri, struct zuf_dispatch_op *zdo)
   645	#endif /* CONFIG_ZUF_DEBUG */
   646	{
   647		struct task_struct *app = get_current();
   648		struct zufs_ioc_hdr *hdr = zdo->hdr;
   649		int cpu;
   650		struct zufc_thread *zt;
   651	
   652		if (unlikely(hdr->out_len && !hdr->out_max)) {
   653			/* TODO: Complain here and let caller code do this proper */
   654			hdr->out_max = hdr->out_len;
   655		}
   656	
   657		if (unlikely(zdo->__locked_zt)) {
   658			zt = zdo->__locked_zt;
   659			zdo->__locked_zt = NULL;
   660	
   661			cpu = get_cpu();
   662			/* FIXME: Very Pedantic need it stay */
   663			if (unlikely((zt->zdo != zdo) || cpu != zt->no)) {
   664				zuf_warn("[%ld] __locked_zt but zdo(%p != %p) || cpu(%d != %d)\n",
   665					 _zt_pr_no(zt), zt->zdo, zdo, cpu, zt->no);
   666				put_cpu();
   667				goto channel_busy;
   668			}
   669			goto has_channel;
   670		}
   671	channel_busy:
   672		cpu = get_cpu();
   673	
   674		if (!_try_grab_zt_channel(zri, cpu, &zt)) {
   675			put_cpu();
   676	
   677			/* If channel was grabbed then maybe a break_all is in progress
   678			 * on a different CPU make sure zt->file on this core is
   679			 * updated
   680			 */
   681			mb();
   682			if (unlikely(!zt->hdr.file)) {
   683				zuf_err("[%d] !zt->file\n", cpu);
   684				return -EIO;
   685			}
   686			zuf_dbg_err("[%d] can this be\n", cpu);
   687			/* FIXME: Do something much smarter */
   688			msleep(10);
   689			if (signal_pending(get_current())) {
   690				zuf_dbg_err("[%d] => EINTR\n", cpu);
   691				return -EINTR;
   692			}
   693			goto channel_busy;
   694		}
   695	
   696		/* lock app to this cpu while waiting */
Quoted 1 line

697 cpumask_copy(&zt->relay.cpus_allowed, &app->cpus_allowed);

   698		cpumask_copy(&app->cpus_allowed,  cpumask_of(smp_processor_id()));
   699	
   700		zt->zdo = zdo;
   701	
   702	has_channel:
   703		if (zdo->dh)
   704			zdo->dh(zdo, zt, zt->opt_buff);
   705		else
   706			memcpy(zt->opt_buff, zt->zdo->hdr, zt->zdo->hdr->in_len);
   707	
   708		put_cpu();
   709	
   710		if (relay_fss_wakeup_app_wait(&zt->relay) == -ERESTARTSYS) {
   711			struct zufs_ioc_hdr *opt_hdr = zt->opt_buff;
   712	
   713			opt_hdr->flags |= ZUFS_H_INTR;
   714	
   715			relay_fss_wakeup_app_wait_cont(&zt->relay);
   716		}
   717	
   718		/* __locked_zt must be kept on same cpu */
   719		if (!zdo->__locked_zt)
   720			/* restore cpu affinity after wakeup */
   721			cpumask_copy(&app->cpus_allowed, &zt->relay.cpus_allowed);
   722	
   723		DEBUG_CPU_SWITCH(cpu);
   724	
   725		return zt->hdr.file ? hdr->err : -EIO;
   726	}
   727	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#8 lore raw

Re: [PATCH 05/16] zuf: zuf-core The ZTs

In reply to Boaz Harrosh
I love your patch! Yet something to improve:

Hi Boaz,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

fs/zuf/zuf-core.c: In function '_r_zufs_dispatch':

>> fs/zuf/zuf-core.c:697:46: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'nr_cpus_allowed'?
     cpumask_copy(&zt->relay.cpus_allowed, &app->cpus_allowed);
                                                 ^~~~~~~~~~~~
                                                 nr_cpus_allowed
   fs/zuf/zuf-core.c:698:21: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'nr_cpus_allowed'?
     cpumask_copy(&app->cpus_allowed,  cpumask_of(smp_processor_id()));
                        ^~~~~~~~~~~~
                        nr_cpus_allowed
   fs/zuf/zuf-core.c:721:22: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'nr_cpus_allowed'?
      cpumask_copy(&app->cpus_allowed, &zt->relay.cpus_allowed);
                         ^~~~~~~~~~~~
                         nr_cpus_allowed

vim +697 fs/zuf/zuf-core.c

643
644 int __zufc_dispatch(struct zuf_root_info *zri, struct zuf_dispatch_op *zdo)
645 #endif /* CONFIG_ZUF_DEBUG */
646 {
647 struct task_struct *app = get_current();
648 struct zufs_ioc_hdr *hdr = zdo->hdr;
649 int cpu;
650 struct zufc_thread *zt;
651
652 if (unlikely(hdr->out_len && !hdr->out_max)) {
653 /* TODO: Complain here and let caller code do this proper */
654 hdr->out_max = hdr->out_len;
655 }
656
657 if (unlikely(zdo->__locked_zt)) {
658 zt = zdo->__locked_zt;
659 zdo->__locked_zt = NULL;
660
661 cpu = get_cpu();
662 /* FIXME: Very Pedantic need it stay */
663 if (unlikely((zt->zdo != zdo) || cpu != zt->no)) {
664 zuf_warn("[%ld] __locked_zt but zdo(%p != %p) || cpu(%d != %d)\n",
665 _zt_pr_no(zt), zt->zdo, zdo, cpu, zt->no);
666 put_cpu();
667 goto channel_busy;
668 }
669 goto has_channel;
670 }
671 channel_busy:
672 cpu = get_cpu();
673
674 if (!_try_grab_zt_channel(zri, cpu, &zt)) {
675 put_cpu();
676
677 /* If channel was grabbed then maybe a break_all is in progress
678 * on a different CPU make sure zt->file on this core is
679 * updated
680 */
681 mb();
682 if (unlikely(!zt->hdr.file)) {
683 zuf_err("[%d] !zt->file\n", cpu);
684 return -EIO;
685 }
686 zuf_dbg_err("[%d] can this be\n", cpu);
687 /* FIXME: Do something much smarter */
688 msleep(10);
689 if (signal_pending(get_current())) {
690 zuf_dbg_err("[%d] => EINTR\n", cpu);
691 return -EINTR;
692 }
693 goto channel_busy;
694 }
695
696 /* lock app to this cpu while waiting */

 > 697		cpumask_copy(&zt->relay.cpus_allowed, &app->cpus_allowed);

698 cpumask_copy(&app->cpus_allowed, cpumask_of(smp_processor_id()));
699
700 zt->zdo = zdo;
701
702 has_channel:
703 if (zdo->dh)
704 zdo->dh(zdo, zt, zt->opt_buff);
705 else
706 memcpy(zt->opt_buff, zt->zdo->hdr, zt->zdo->hdr->in_len);
707
708 put_cpu();
709
710 if (relay_fss_wakeup_app_wait(&zt->relay) == -ERESTARTSYS) {
711 struct zufs_ioc_hdr *opt_hdr = zt->opt_buff;
712
713 opt_hdr->flags |= ZUFS_H_INTR;
714
715 relay_fss_wakeup_app_wait_cont(&zt->relay);
716 }
717
718 /* __locked_zt must be kept on same cpu */
719 if (!zdo->__locked_zt)
720 /* restore cpu affinity after wakeup */
721 cpumask_copy(&app->cpus_allowed, &zt->relay.cpus_allowed);
722
723 DEBUG_CPU_SWITCH(cpu);
724
725 return zt->hdr.file ? hdr->err : -EIO;
726 }
727

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#9 lore raw

PATCH 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.

---
 fs/zuf/Makefile   |   3 +
 fs/zuf/_extern.h  |   6 +
 fs/zuf/md.c       | 742 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/md.h       | 332 +++++++++++++++++++++
 fs/zuf/md_def.h   | 145 +++++++++
 fs/zuf/super.c    |   6 +
 fs/zuf/t1.c       | 135 +++++++++
 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, 1938 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 +145 -0

145 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 +135 -0

135 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 c3a2f7c0e0cd..653ca24c9c92 100644
@@ -22,6 +22,8 @@
 #include <linux/fiemap.h>
 #include <stddef.h>
 
+#include "md_def.h"
+
 #ifdef __cplusplus
 #define NAMELESS(X) X
 #else
@@ -359,6 +361,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.20.1
#10 lore raw

Re: [PATCH 06/16] zuf: Multy Devices

I love your patch! Perhaps something to improve:

Hi Boaz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to v5.3-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

In file included from include/linux/kernel.h:15:0,

                    from include/asm-generic/bug.h:18,
                    from arch/x86/include/asm/bug.h:83,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/mm.h:9,
                    from fs/zuf/t1.c:15:
   fs/zuf/t1.c: In function 't1_fault':
   include/linux/printk.h:304:2: warning: this statement may fall through [-Wimplicit-fallthrough=]
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> fs/zuf/_pr.h:23:31: note: in expansion of macro 'pr_err'
    #define zuf_err(s, args ...)  pr_err("[%s:%d] " s, __func__, \
                                  ^~~~~~
>> fs/zuf/t1.c:75:3: note: in expansion of macro 'zuf_err'
      zuf_err("[%ld] PTE fault not expected pgoff=0x%lx addr=0x%lx\n",
      ^~~~~~~
   fs/zuf/t1.c:78:2: note: here
     case PE_SIZE_PMD:
     ^~~~

vim +/pr_err +23 fs/zuf/_pr.h

f577115420e717 Boaz Harrosh 2019-08-12  19  
f577115420e717 Boaz Harrosh 2019-08-12  20  /*
f577115420e717 Boaz Harrosh 2019-08-12  21   * Debug code
f577115420e717 Boaz Harrosh 2019-08-12  22   */
f577115420e717 Boaz Harrosh 2019-08-12 @23  #define zuf_err(s, args ...)		pr_err("[%s:%d] " s, __func__, \
f577115420e717 Boaz Harrosh 2019-08-12  24  							__LINE__, ## args)
f577115420e717 Boaz Harrosh 2019-08-12  25  #define zuf_err_cnd(silent, s, args ...) \
f577115420e717 Boaz Harrosh 2019-08-12  26  	do {if (!silent) \
f577115420e717 Boaz Harrosh 2019-08-12  27  		pr_err("[%s:%d] " s, __func__, __LINE__, ## args); \
f577115420e717 Boaz Harrosh 2019-08-12  28  	} while (0)
f577115420e717 Boaz Harrosh 2019-08-12  29  #define zuf_warn(s, args ...)		pr_warn("[%s:%d] " s, __func__, \
f577115420e717 Boaz Harrosh 2019-08-12  30  							__LINE__, ## args)
f577115420e717 Boaz Harrosh 2019-08-12  31  #define zuf_warn_cnd(silent, s, args ...) \
f577115420e717 Boaz Harrosh 2019-08-12  32  	do {if (!silent) \
f577115420e717 Boaz Harrosh 2019-08-12  33  		pr_warn("[%s:%d] " s, __func__, __LINE__, ## args); \
f577115420e717 Boaz Harrosh 2019-08-12  34  	} while (0)
f577115420e717 Boaz Harrosh 2019-08-12  35  #define zuf_info(s, args ...)          pr_info("~info~ " s, ## args)

f577115420e717 Boaz Harrosh 2019-08-12 36

:::::: The code at line 23 was first introduced by commit :::::: f577115420e717e536986a2e6055c584ec2f6829 zuf: zuf-rootfs

:::::: TO: Boaz Harrosh <[email protected]> :::::: CC: 0day robot <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#11 lore raw

Re: [PATCH 06/16] zuf: Multy Devices

Quoted 31 lines · kbuild test robot

Hi Boaz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to v5.3-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

   In file included from include/linux/kernel.h:15:0,
                    from include/asm-generic/bug.h:18,
                    from arch/x86/include/asm/bug.h:83,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/mm.h:9,
                    from fs/zuf/t1.c:15:
   fs/zuf/t1.c: In function 't1_fault':
   include/linux/printk.h:304:2: warning: this statement may fall through [-Wimplicit-fallthrough=]
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Quoted 1 line
Quoted 1 line

fs/zuf/_pr.h:23:31: note: in expansion of macro 'pr_err'

    #define zuf_err(s, args ...)  pr_err("[%s:%d] " s, __func__, \
                                  ^~~~~~
Quoted 1 line
Quoted 1 line

fs/zuf/t1.c:75:3: note: in expansion of macro 'zuf_err'

      zuf_err("[%ld] PTE fault not expected pgoff=0x%lx addr=0x%lx\n",
      ^~~~~~~

I do not understand how to fix this problem.
There is an explicit comment that says this is an intentional fall through. here is the complete code:

	switch (pe_size) {
	case PE_SIZE_PTE:
		zuf_err("[%ld] PTE fault not expected pgoff=0x%lx addr=0x%lx\n",
			inode->i_ino, vmf->pgoff, addr);
		/* fall through do PMD insert anyway */
	case PE_SIZE_PMD:
		bn = linear_page_index(vma, addr & PMD_MASK);
		pfn = md_pfn(z_pmem->md, bn);
	....

Please advise on how to make your compiler happy?

Thanks
Boaz

Quoted 35 lines
   fs/zuf/t1.c:78:2: note: here
     case PE_SIZE_PMD:
     ^~~~

vim +/pr_err +23 fs/zuf/_pr.h

f577115420e717 Boaz Harrosh 2019-08-12  19  
f577115420e717 Boaz Harrosh 2019-08-12  20  /*
f577115420e717 Boaz Harrosh 2019-08-12  21   * Debug code
f577115420e717 Boaz Harrosh 2019-08-12  22   */
f577115420e717 Boaz Harrosh 2019-08-12 @23  #define zuf_err(s, args ...)		pr_err("[%s:%d] " s, __func__, \
f577115420e717 Boaz Harrosh 2019-08-12  24  							__LINE__, ## args)
f577115420e717 Boaz Harrosh 2019-08-12  25  #define zuf_err_cnd(silent, s, args ...) \
f577115420e717 Boaz Harrosh 2019-08-12  26  	do {if (!silent) \
f577115420e717 Boaz Harrosh 2019-08-12  27  		pr_err("[%s:%d] " s, __func__, __LINE__, ## args); \
f577115420e717 Boaz Harrosh 2019-08-12  28  	} while (0)
f577115420e717 Boaz Harrosh 2019-08-12  29  #define zuf_warn(s, args ...)		pr_warn("[%s:%d] " s, __func__, \
f577115420e717 Boaz Harrosh 2019-08-12  30  							__LINE__, ## args)
f577115420e717 Boaz Harrosh 2019-08-12  31  #define zuf_warn_cnd(silent, s, args ...) \
f577115420e717 Boaz Harrosh 2019-08-12  32  	do {if (!silent) \
f577115420e717 Boaz Harrosh 2019-08-12  33  		pr_warn("[%s:%d] " s, __func__, __LINE__, ## args); \
f577115420e717 Boaz Harrosh 2019-08-12  34  	} while (0)
f577115420e717 Boaz Harrosh 2019-08-12  35  #define zuf_info(s, args ...)          pr_info("~info~ " s, ## args)

f577115420e717 Boaz Harrosh 2019-08-12 36

:::::: The code at line 23 was first introduced by commit :::::: f577115420e717e536986a2e6055c584ec2f6829 zuf: zuf-rootfs

:::::: TO: Boaz Harrosh <[email protected]> :::::: CC: 0day robot <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#12 lore raw

PATCH 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 DT) 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 despatches 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 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 lockdown 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. Infact in zus the code feels exactly the same as a live mount. (See the zus project for more info)

---
 fs/zuf/Makefile   |   2 +-
 fs/zuf/_extern.h  |   7 +
 fs/zuf/inode.c    |  23 ++
 fs/zuf/super.c    | 777 +++++++++++++++++++++++++++++++++++++++++++++-
 fs/zuf/zuf-core.c |  95 ++++++
 fs/zuf/zuf.h      | 119 +++++++
 fs/zuf/zus_api.h  |  35 +++
 7 files changed, 1055 insertions(+), 3 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 +7 -0
index a5929d3d165c..ba6d11b509d5 100644
@@ -57,6 +57,13 @@ struct dentry *zuf_mount(struct file_system_type *fs_type, int flags,
 struct super_block *zuf_sb_from_id(struct zuf_root_info *zri, __u64 sb_id,
 				   struct zus_sb_info *zus_sbi);
 
+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);
+
+/* 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 +775 -2

801 lines not on this page · raw message

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

119 lines not on this page · raw message

fs/zuf/zuf.h +119 -0

137 lines not on this page · raw message

fs/zuf/zus_api.h +35 -0
index 653ca24c9c92..c7681c53700c 100644
@@ -334,6 +334,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];
@@ -436,7 +447,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.20.1
#13 lore raw

Re: [PATCH 07/16] zuf: mounting

I love your patch! Perhaps something to improve:

Hi Boaz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to v5.3-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

fs/zuf/zuf-core.c: In function '_r_zufs_dispatch':
fs/zuf/zuf-core.c:860:46: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'nr_cpus_allowed'?

     cpumask_copy(&zt->relay.cpus_allowed, &app->cpus_allowed);
                                                 ^~~~~~~~~~~~
                                                 nr_cpus_allowed
   fs/zuf/zuf-core.c:861:21: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'nr_cpus_allowed'?
     cpumask_copy(&app->cpus_allowed,  cpumask_of(smp_processor_id()));
                        ^~~~~~~~~~~~
                        nr_cpus_allowed
   fs/zuf/zuf-core.c:884:22: error: 'struct task_struct' has no member named 'cpus_allowed'; did you mean 'nr_cpus_allowed'?
      cpumask_copy(&app->cpus_allowed, &zt->relay.cpus_allowed);
                         ^~~~~~~~~~~~
                         nr_cpus_allowed
   fs/zuf/zuf-core.c: In function 'zufc_release':
>> fs/zuf/zuf-core.c:1078:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
      _zu_private_mounter_release(file);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/zuf/zuf-core.c:1079:2: note: here
     case zlfs_e_pmem:
     ^~~~

vim +1078 fs/zuf/zuf-core.c

1062
1063 int zufc_release(struct inode *inode, struct file *file)
1064 {
1065 struct zuf_special_file *zsf = file->private_data;
1066
1067 if (!zsf)
1068 return 0;
1069
1070 switch (zsf->type) {
1071 case zlfs_e_zt:
1072 zufc_zt_release(file);
1073 return 0;
1074 case zlfs_e_mout_thread:
1075 zufc_mounter_release(file);
1076 return 0;
1077 case zlfs_e_private_mount:

> 1078			_zu_private_mounter_release(file);

1079 case zlfs_e_pmem:
1080 /* NOTHING to clean for pmem file yet */
1081 /* zuf_pmem_release(file);*/
1082 return 0;
1083 case zlfs_e_dpp_buff:
1084 zufc_ebuff_release(file);
1085 return 0;
1086 default:
1087 return 0;
1088 }
1089 }
1090

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#14 lore raw

PATCH 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   |  44 ++++
 fs/zuf/directory.c | 100 ++++++++
 fs/zuf/file.c      |  41 ++++
 fs/zuf/inode.c     | 563 ++++++++++++++++++++++++++++++++++++++++++++-
 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, 1319 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 +44 -0

54 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 +41 -0

41 lines not on this page · raw message

fs/zuf/inode.c +562 -1

573 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 859d4e3884ec..49f2c62e22b7 100644
@@ -781,6 +781,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 301cf5058231..d2a2cd28b5e3 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.20.1
#15 lore raw

PATCH 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.

---
 fs/zuf/directory.c | 65 +++++++++++++++++++++++++++++++++-
 fs/zuf/zuf-core.c  |  2 ++
 fs/zuf/zus_api.h   | 88 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 154 insertions(+), 1 deletion(-)
fs/zuf/directory.c +64 -1
index 5624e05f96e5..645dd367fd8c 100644
@@ -19,7 +19,70 @@
 
 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[ZUS_API_MAP_MAX_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);
+	addr = vzalloc(md_p2o(nump));
+	if (unlikely(!addr))
+		return -ENOMEM;
+
+	WARN_ON((ulong)addr & (PAGE_SIZE - 1));
+
+	__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("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 d2a2cd28b5e3..12fff87e0b47 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.20.1

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

#17 lore raw

Re: [PATCH 09/16] zuf: readdir operation

Quoted 2 lines · kbuild test robot

Hi Boaz,

<>

Quoted 6 lines

fs/zuf/directory.c: In function 'zuf_readdir':

Quoted 1 line
Quoted 1 line

fs/zuf/directory.c:86:1: warning: the frame size of 8576 bytes is larger than 8192 bytes [-Wframe-larger-than=]

    }
    ^

Will fix thank you
Boaz

#18 lore raw

PATCH 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 bf4531ccb80e..918a6510e635 100644
@@ -90,6 +90,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);
 
@@ -111,4 +115,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 0e6d835b4db5..539b40ecbc47 100644
@@ -85,6 +85,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:
@@ -350,6 +353,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.20.1
#19 lore raw

PATCH 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.

---
 fs/zuf/Makefile   |   1 +
 fs/zuf/_extern.h  |  24 ++
 fs/zuf/file.c     |  67 +++-
 fs/zuf/inode.c    |  74 ++++
 fs/zuf/rw.c       | 960 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf-core.c | 395 ++++++++++++++++++-
 fs/zuf/zuf.h      |   7 +
 fs/zuf/zus_api.h  | 251 ++++++++++++
 8 files changed, 1775 insertions(+), 4 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 +24 -0
index 918a6510e635..724c6c5e5d3c 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);
@@ -94,6 +97,27 @@ 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_rw_fadvise(struct super_block *sb, struct inode *inode,
+		   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,
+			 __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 +65 -2

87 lines not on this page · raw message

fs/zuf/inode.c +74 -0

85 lines not on this page · raw message

fs/zuf/rw.c new file +960 -0

960 lines not on this page · raw message

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

475 lines not on this page · raw message

fs/zuf/zuf.h +7 -0
index cc9a26b17e8e..04e962d7db86 100644
@@ -386,6 +386,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.20.1
#20 lore raw

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

I love your patch! Perhaps something to improve:

Hi Boaz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to v5.3-rc4 next-20190813]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

fs/zuf/rw.c: In function '_zufs_IO.isra.18':

>> fs/zuf/rw.c:371:1: warning: the frame size of 8712 bytes is larger than 8192 bytes [-Wframe-larger-than=]
    }
    ^
   fs/zuf/rw.c: In function '_IO_gm_inner':
   fs/zuf/rw.c:569:1: warning: the frame size of 8720 bytes is larger than 8192 bytes [-Wframe-larger-than=]
    }
    ^

vim +371 fs/zuf/rw.c

303
304 static ssize_t _zufs_IO(struct zuf_sb_info *sbi, struct inode *inode,
305 struct iov_iter *ii, struct kiocb *kiocb,
306 struct file_ra_state *ra, int operation, uint rw)
307 {
308 int err = 0;
309 loff_t start_pos = kiocb->ki_pos;
310 loff_t pos = start_pos;
311
312 while (iov_iter_count(ii)) {
313 struct zufs_ioc_IO io = {};
314 struct page *pages[ZUS_API_MAP_MAX_PAGES];
315 uint nump;
316 ssize_t bytes;
317 size_t pgoffset;
318 uint i;
319
320 if (ra) {
321 io.ra.start = ra->start;
322 io.ra.ra_pages = ra->ra_pages;
323 io.ra.prev_pos = ra->prev_pos;
324 }
325 io.rw = rw;
326
327 bytes = _iov_iter_get_pages_any(ii, pages,
328 ZUS_API_MAP_MAX_SIZE,
329 ZUS_API_MAP_MAX_PAGES, &pgoffset);
330 if (unlikely(bytes < 0)) {
331 err = bytes;
332 break;
333 }
334
335 nump = DIV_ROUND_UP(bytes + pgoffset, PAGE_SIZE);
336
337 io.last_pos = pos;
338 err = _IO_dispatch(sbi, &io, ZUII(inode), operation,
339 pgoffset, pages, nump, pos, bytes);
340
341 bytes = io.last_pos - pos;
342
343 zuf_dbg_rw("[%ld] %s [0x%llx-0x%zx]\n",
344 inode->i_ino, _pr_rw(rw), pos, bytes);
345
346 iov_iter_advance(ii, bytes);
347 pos += bytes;
348
349 if (ra) {
350 ra->start = io.ra.start;
351 ra->ra_pages = io.ra.ra_pages;
352 ra->prev_pos = io.ra.prev_pos;
353 }
354 if (io.wr_unmap.len)
355 unmap_mapping_range(inode->i_mapping,
356 io.wr_unmap.offset,
357 io.wr_unmap.len, 0);
358
359 for (i = 0; i < nump; ++i)
360 put_page(pages[i]);
361
362 if (unlikely(err))
363 break;
364 }
365
366 if (unlikely(pos == start_pos))
367 return err;
368
369 kiocb->ki_pos = pos;
370 return pos - start_pos;

 > 371	}

372

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#21 lore raw

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

On 13/08/2019 13:23, kbuild test robot wrote:
<>

Quoted 3 lines
   fs/zuf/rw.c: In function '_zufs_IO.isra.18':
Quoted 1 line
Quoted 1 line

fs/zuf/rw.c:371:1: warning: the frame size of 8712 bytes is larger than 8192 bytes [-Wframe-larger-than=]

Will fix
Boaz

Quoted 4 lines
    }
    ^

fs/zuf/rw.c: In function '_IO_gm_inner':
fs/zuf/rw.c:569:1: warning: the frame size of 8720 bytes is larger than 8192 bytes [-Wframe-larger-than=]

<>

#22 lore raw

PATCH 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.

---
 fs/zuf/Makefile   |   2 +-
 fs/zuf/_extern.h  |   6 +
 fs/zuf/file.c     |  67 +++++++++++
 fs/zuf/inode.c    |  11 ++
 fs/zuf/mmap.c     | 300 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/rw.c       |  17 +++
 fs/zuf/super.c    |  89 ++++++++++++++
 fs/zuf/zuf-core.c |   2 +
 fs/zuf/zuf.h      |   3 +
 fs/zuf/zus_api.h  |  26 ++++
 10 files changed, 522 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 724c6c5e5d3c..34fde591cf92 100644
@@ -54,6 +54,9 @@ int zufr_register_fs(struct super_block *sb, struct zufs_ioc_register_fs *rfs);
 int zuf_init_inodecache(void);
 void zuf_destroy_inodecache(void);
 
+void zuf_sync_inc(struct inode *inode);
+void zuf_sync_dec(struct inode *inode, ulong write_unmapped);
+
 struct dentry *zuf_mount(struct file_system_type *fs_type, int flags,
 			 const char *dev_name, void *data);
 
@@ -118,6 +121,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 +67 -0

79 lines not on this page · raw message

fs/zuf/inode.c +11 -0
index b4d06fe6bf89..567fb4117371 100644
@@ -273,6 +273,8 @@ void zuf_evict_inode(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
 	struct zuf_inode_info *zii = ZUII(inode);
+	int write_mapped;
+
 	zufc_goose_all_zts(ZUF_ROOT(SBI(sb)), inode);
 
 	if (!inode->i_nlink) {
@@ -310,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/rw.c +17 -0
index 4048d52b48ba..6107dcb801a3 100644
@@ -649,12 +649,29 @@ static int _fadv_willneed(struct super_block *sb, struct inode *inode,
 	return err;
 }
 
+static int _fadv_dontneed(struct super_block *sb, struct inode *inode,
+			  loff_t offset, loff_t len)
+{
+	struct zufs_ioc_sync ioc_range = {
+		.hdr.in_len = sizeof(ioc_range),
+		.hdr.operation = ZUFS_OP_SYNC,
+		.zus_ii = ZUII(inode)->zus_ii,
+		.offset = offset,
+		.length = len,
+		.flags = ZUFS_SF_DONTNEED,
+	};
+
+	return zufc_dispatch(ZUF_ROOT(SBI(sb)), &ioc_range.hdr, NULL, 0);
+}
+
 int zuf_rw_fadvise(struct super_block *sb, struct inode *inode,
 		   loff_t offset, loff_t len, int advise, bool rand)
 {
 	switch (advise) {
 	case POSIX_FADV_WILLNEED:
 		return _fadv_willneed(sb, inode, offset, len, rand);
+	case POSIX_FADV_DONTNEED:
+		return _fadv_dontneed(sb, inode, offset, len);
 	case POSIX_FADV_NOREUSE: /* TODO */
 	case POSIX_FADV_SEQUENTIAL: /* TODO: turn off random */
 	case POSIX_FADV_NORMAL:
fs/zuf/super.c +89 -0

108 lines not on this page · raw message

fs/zuf/zuf-core.c +2 -0
index 449f47272072..ff04c6912c17 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 04e962d7db86..e78515d7a3fe 100644
@@ -131,6 +131,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 3e7160c48ba8..42d3086a4262 100644
@@ -463,7 +463,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,
@@ -649,6 +651,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;
@@ -658,6 +667,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.20.1
#23 lore raw

PATCH 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 rw,c)
.fiemap zuf_fiemap ZUFS_OP_FIEMAP

See more comments in source code.

---
 fs/zuf/file.c     | 664 +++++++++++++++++++++++++++++++++++++++++++++-
 fs/zuf/zuf-core.c |   5 +
 fs/zuf/zus_api.h  |  83 ++++++
 3 files changed, 751 insertions(+), 1 deletion(-)
fs/zuf/file.c +663 -1
index 58142c825230..b7657e8c7e0a 100644
@@ -15,12 +15,158 @@
 
 #include <linux/fs.h>
 #include <linux/uio.h>
+#include <linux/falloc.h>
+#include <linux/fadvise.h>
+#include <linux/sched/signal.h>
 
 #include "zuf.h"
 
 long __zuf_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)
 {
-	return -ENOTSUPP;
+	struct zuf_inode_info *zii = ZUII(inode);
+	bool need_len_check, need_unmap;
+	loff_t unmap_len = 0; /* 0 means all file */
+	loff_t new_size = len + offset;
+	loff_t i_size = i_size_read(inode);
+	int err = 0;
+
+	zuf_dbg_vfs("[%ld] mode=0x%x offset=0x%llx len=0x%llx\n",
+		     inode->i_ino, mode, offset, len);
+
+	if (!S_ISREG(inode->i_mode))
+		return -EINVAL;
+	if (IS_SWAPFILE(inode))
+		return -ETXTBSY;
+
+	/* These are all the FL flags we know how to handle on the  kernel side
+	 * a zusFS that does not support one of these can just return
+	 * EOPNOTSUPP.
+	 */
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
+		     FALLOC_FL_NO_HIDE_STALE | FALLOC_FL_COLLAPSE_RANGE |
+		     FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE |
+		     FALLOC_FL_UNSHARE_RANGE | ZUFS_FL_TRUNCATE)){
+		zuf_dbg_err("Unsupported mode(0x%x)\n", mode);
+		return -EOPNOTSUPP;
+	}
+
+	if (mode & FALLOC_FL_PUNCH_HOLE) {
+		need_len_check = false;
+		need_unmap = true;
+		unmap_len = len;
+	} else if (mode & ZUFS_FL_TRUNCATE) {
+		need_len_check = true;
+		new_size = offset;
+		need_unmap = true;
+	} else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
+		need_len_check = false;
+		need_unmap = true;
+	} else if (mode & FALLOC_FL_INSERT_RANGE) {
+		need_len_check = true;
+		new_size = i_size + len;
+		need_unmap = true;
+	} else if (mode & FALLOC_FL_ZERO_RANGE) {
+		need_len_check = !(mode & FALLOC_FL_KEEP_SIZE);
+		need_unmap = true;
+	} else {
+		/* FALLOC_FL_UNSHARE_RANGE same as regular */
+		need_len_check = !(mode & FALLOC_FL_KEEP_SIZE);
+		need_unmap = false;
+	}
+
+	if (need_len_check && (new_size > i_size)) {
+		err = inode_newsize_ok(inode, new_size);
+		if (unlikely(err)) {
+			zuf_dbg_err("inode_newsize_ok(0x%llx) => %d\n",
+				    new_size, err);
+			goto out;
+		}
+	}
+
+	if (need_unmap) {
+		zufc_goose_all_zts(ZUF_ROOT(SBI(inode->i_sb)), inode);
+		unmap_mapping_range(inode->i_mapping, offset, unmap_len, 1);
+	}
+
+	zus_inode_cmtime_now(inode, zii->zi);
+
+	err = zuf_rw_fallocate(inode, mode, offset, len);
+
+	/* Even if we had an error these might have changed */
+	i_size_write(inode, le64_to_cpu(zii->zi->i_size));
+	inode->i_blocks = le64_to_cpu(zii->zi->i_blocks);
+
+out:
+	return err;
+}
+
+static long zuf_fallocate(struct file *file, int mode, loff_t offset,
+			  loff_t len)
+{
+	struct inode *inode = file->f_inode;
+	struct zuf_inode_info *zii = ZUII(inode);
+	int err;
+
+	zuf_w_lock(zii);
+
+	err = __zuf_fallocate(inode, mode, offset, len);
+
+	zuf_w_unlock(zii);
+	return err;
+}
+
+static loff_t zuf_llseek(struct file *file, loff_t offset, int whence)
+{
+	struct inode *inode = file->f_path.dentry->d_inode;
+	struct zuf_inode_info *zii = ZUII(inode);
+	struct zufs_ioc_seek ioc_seek = {
+		.hdr.in_len = sizeof(ioc_seek),
+		.hdr.out_len = sizeof(ioc_seek),
+		.hdr.operation = ZUFS_OP_LLSEEK,
+		.zus_ii = zii->zus_ii,
+		.offset_in = offset,
+		.whence = whence,
+	};
+	int err = 0;
+
+	zuf_dbg_vfs("[%ld] offset=0x%llx whence=%d\n",
+		     inode->i_ino, offset, whence);
+
+	if (whence != SEEK_DATA && whence != SEEK_HOLE)
+		return generic_file_llseek(file, offset, whence);
+
+	zuf_r_lock(zii);
+
+	if ((offset < 0 && !(file->f_mode & FMODE_UNSIGNED_OFFSET)) ||
+	    offset > inode->i_sb->s_maxbytes) {
+		err = -EINVAL;
+		goto out;
+	} else if (inode->i_size <= offset) {
+		err = -ENXIO;
+		goto out;
+	} else if (!inode->i_blocks) {
+		if (whence == SEEK_HOLE)
+			ioc_seek.offset_out = i_size_read(inode);
+		else
+			err = -ENXIO;
+		goto out;
+	}
+
+	err = zufc_dispatch(ZUF_ROOT(SBI(inode->i_sb)), &ioc_seek.hdr, NULL, 0);
+	if (unlikely(err)) {
+		zuf_dbg_err("zufc_dispatch failed => %d\n", err);
+		goto out;
+	}
+
+	if (ioc_seek.offset_out != file->f_pos) {
+		file->f_pos = ioc_seek.offset_out;
+		file->f_version = 0;
+	}
+
+out:
+	zuf_r_unlock(zii);
+
+	return err ?: ioc_seek.offset_out;
 }
 
 /* This function is called by both msync() and fsync(). */
@@ -87,6 +233,494 @@ static int zuf_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 	return zuf_isync(file_inode(file), start, end, datasync);
 }
 
+/* This callback is called when a file is closed */
+static int zuf_flush(struct file *file, fl_owner_t id)
+{
+	zuf_dbg_vfs("[%ld]\n", file->f_inode->i_ino);
+
+	return 0;
+}
+
+static int zuf_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		      u64 offset, u64 len)
+{
+	struct super_block *sb = inode->i_sb;
+	struct zuf_inode_info *zii = ZUII(inode);
+	struct zufs_ioc_fiemap ioc_fiemap = {
+		.hdr.operation = ZUFS_OP_FIEMAP,
+		.hdr.in_len = sizeof(ioc_fiemap),
+		.hdr.out_len = sizeof(ioc_fiemap),
+		.zus_ii = zii->zus_ii,
+		.start = offset,
+		.length = len,
+		.flags = fieinfo->fi_flags,
+	};
+	struct page *pages[ZUS_API_MAP_MAX_PAGES];
+	uint nump = 0, extents_max = 0;
+	int i, err;
+
+	zuf_dbg_vfs("[%ld] offset=0x%llx len=0x%llx extents_max=%u flags=0x%x\n",
+		    inode->i_ino, offset, len, fieinfo->fi_extents_max,
+		    fieinfo->fi_flags);
+
+	/* TODO: Have support for FIEMAP_FLAG_XATTR */
+	err = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
+	if (unlikely(err))
+		return err;
+
+	if (likely(fieinfo->fi_extents_max)) {
+		ulong start = (ulong)fieinfo->fi_extents_start;
+		ulong len = fieinfo->fi_extents_max *
+						sizeof(struct fiemap_extent);
+		ulong offset = start & (PAGE_SIZE - 1);
+		ulong end_offset = (offset + len) & (PAGE_SIZE - 1);
+		ulong __len;
+		uint nump_r;
+
+		nump = md_o2p_up(offset + len);
+		if (ARRAY_SIZE(pages) < nump) {
+			nump = ARRAY_SIZE(pages);
+			end_offset = 0;
+		}
+
+		nump_r = get_user_pages_fast(start, nump, WRITE, pages);
+		if (unlikely(nump != nump_r))
+			return -EFAULT;
+
+		__len = nump * PAGE_SIZE - offset;
+		if (end_offset)
+			__len -= (PAGE_SIZE - end_offset);
+
+		extents_max = __len / sizeof(struct fiemap_extent);
+
+		ioc_fiemap.hdr.len = extents_max * sizeof(struct fiemap_extent);
+		ioc_fiemap.hdr.offset = offset;
+	}
+	ioc_fiemap.extents_max = extents_max;
+
+	zuf_r_lock(zii);
+
+	err = zufc_dispatch(ZUF_ROOT(SBI(sb)), &ioc_fiemap.hdr, pages, nump);
+	if (unlikely(err)) {
+		zuf_dbg_err("zufs_dispatch failed => %d\n", err);
+		goto out;
+	}
+
+	fieinfo->fi_extents_mapped = ioc_fiemap.extents_mapped;
+	if (unlikely(extents_max &&
+		     (extents_max < ioc_fiemap.extents_mapped))) {
+		zuf_err("extents_max=%d extents_mapped=%d\n", extents_max,
+			ioc_fiemap.extents_mapped);
+		err = -EINVAL;
+	}
+
+out:
+	zuf_r_unlock(zii);
+
+	for (i = 0; i < nump; ++i)
+		put_page(pages[i]);
+
+	return err;
+}
+
+/* ~~~~~ clone/copy range ~~~~~ */
+
+/*
+ * Copy/paste from Kernel mm/filemap.c::generic_remap_checks
+ * FIXME: make it EXPORT_GPL
+ */
+static int _access_check_limits(struct file *file, loff_t pos,
+				       loff_t *count)
+{
+	struct inode *inode = file->f_mapping->host;
+	loff_t max_size = inode->i_sb->s_maxbytes;
+
+	if (!(file->f_flags & O_LARGEFILE))
+		max_size = MAX_NON_LFS;
+
+	if (unlikely(pos >= max_size))
+		return -EFBIG;
+	*count = min(*count, max_size - pos);
+	return 0;
+}
+
+static int _write_check_limits(struct file *file, loff_t pos,
+				      loff_t *count)
+{
+
+	loff_t limit = rlimit(RLIMIT_FSIZE);
+
+	if (limit != RLIM_INFINITY) {
+		if (pos >= limit) {
+			send_sig(SIGXFSZ, current, 0);
+			return -EFBIG;
+		}
+		*count = min(*count, limit - pos);
+	}
+
+	return _access_check_limits(file, pos, count);
+}
+
+static int _remap_checks(struct file *file_in, loff_t pos_in,
+			 struct file *file_out, loff_t pos_out,
+			 loff_t *req_count, unsigned int remap_flags)
+{
+	struct inode *inode_in = file_in->f_mapping->host;
+	struct inode *inode_out = file_out->f_mapping->host;
+	uint64_t count = *req_count;
+	uint64_t bcount;
+	loff_t size_in, size_out;
+	loff_t bs = inode_out->i_sb->s_blocksize;
+	int ret;
+
+	/* The start of both ranges must be aligned to an fs block. */
+	if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_out, bs))
+		return -EINVAL;
+
+	/* Ensure offsets don't wrap. */
+	if (pos_in + count < pos_in || pos_out + count < pos_out)
+		return -EINVAL;
+
+	size_in = i_size_read(inode_in);
+	size_out = i_size_read(inode_out);
+
+	/* Dedupe requires both ranges to be within EOF. */
+	if ((remap_flags & REMAP_FILE_DEDUP) &&
+	    (pos_in >= size_in || pos_in + count > size_in ||
+	     pos_out >= size_out || pos_out + count > size_out))
+		return -EINVAL;
+
+	/* Ensure the infile range is within the infile. */
+	if (pos_in >= size_in)
+		return -EINVAL;
+	count = min(count, size_in - (uint64_t)pos_in);
+
+	ret = _access_check_limits(file_in, pos_in, &count);
+	if (ret)
+		return ret;
+
+	ret = _write_check_limits(file_out, pos_out, &count);
+	if (ret)
+		return ret;
+
+	/*
+	 * If the user wanted us to link to the infile's EOF, round up to the
+	 * next block boundary for this check.
+	 *
+	 * Otherwise, make sure the count is also block-aligned, having
+	 * already confirmed the starting offsets' block alignment.
+	 */
+	if (pos_in + count == size_in) {
+		bcount = ALIGN(size_in, bs) - pos_in;
+	} else {
+		if (!IS_ALIGNED(count, bs))
+			count = ALIGN_DOWN(count, bs);
+		bcount = count;
+	}
+
+	/* Don't allow overlapped cloning within the same file. */
+	if (inode_in == inode_out &&
+	    pos_out + bcount > pos_in &&
+	    pos_out < pos_in + bcount)
+		return -EINVAL;
+
+	/*
+	 * We shortened the request but the caller can't deal with that, so
+	 * bounce the request back to userspace.
+	 */
+	if (*req_count != count && !(remap_flags & REMAP_FILE_CAN_SHORTEN))
+		return -EINVAL;
+
+	*req_count = count;
+	return 0;
+}
+
+/*
+ * Copy/paste from generic_remap_file_range_prep(). We cannot call
+ * generic_remap_file_range_prep because it calles fsync twice and we do not
+ * want to go to the Server so many times.
+ * So below is just the checks.
+ * FIXME: Send a patch upstream to split the generic_remap_file_range_prep
+ * or receive a flag if to do the syncs
+ *
+ * Check that the two inodes are eligible for cloning, the ranges make
+ * sense.
+ *
+ * If there's an error, then the usual negative error code is returned.
+ * Otherwise returns 0 with *len set to the request length.
+ */
+static int _remap_file_range_prep(struct file *file_in, loff_t pos_in,
+				  struct file *file_out, loff_t pos_out,
+				  loff_t *len, unsigned int remap_flags)
+{
+	struct inode *inode_in = file_inode(file_in);
+	struct inode *inode_out = file_inode(file_out);
+	int ret;
+
+	/* Don't touch certain kinds of inodes */
+	if (IS_IMMUTABLE(inode_out))
+		return -EPERM;
+
+	if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out))
+		return -ETXTBSY;
+
+	/* Don't reflink dirs, pipes, sockets... */
+	if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
+		return -EISDIR;
+	if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
+		return -EINVAL;
+
+	/* Zero length dedupe exits immediately; reflink goes to EOF. */
+	if (*len == 0) {
+		loff_t isize = i_size_read(inode_in);
+
+		if ((remap_flags & REMAP_FILE_DEDUP) || pos_in == isize)
+			return 0;
+		if (pos_in > isize)
+			return -EINVAL;
+		*len = isize - pos_in;
+		if (*len == 0)
+			return 0;
+	}
+
+	/* Check that we don't violate system file offset limits. */
+	ret = _remap_checks(file_in, pos_in, file_out, pos_out, len,
+			    remap_flags);
+	if (ret)
+		return ret;
+
+	/*
+	 * REMAP_FILE_DEDUP see if extents are the same.
+	 */
+	if (remap_flags & REMAP_FILE_DEDUP)
+		ret = zuf_rw_file_range_compare(inode_in, pos_in,
+						inode_out, pos_out, *len);
+
+	return ret;
+}
+
+static void _lock_two_ziis(struct zuf_inode_info *zii1,
+			   struct zuf_inode_info *zii2)
+{
+	if (zii1 > zii2)
+		swap(zii2, zii2);
+
+	zuf_w_lock(zii1);
+	if (zii1 != zii2)
+		zuf_w_lock_nested(zii2);
+}
+
+static void _unlock_two_ziis(struct zuf_inode_info *zii1,
+		      struct zuf_inode_info *zii2)
+{
+	if (zii1 > zii2)
+		swap(zii2, zii2);
+
+	if (zii1 != zii2)
+		zuf_w_unlock(zii2);
+	zuf_w_unlock(zii1);
+}
+
+static int _clone_file_range(struct inode *src_inode, loff_t pos_in,
+			     struct file *file_out,
+			     struct inode *dst_inode, loff_t pos_out,
+			     u64 len, u64 len_up, int operation)
+{
+	struct zuf_inode_info *src_zii = ZUII(src_inode);
+	struct zuf_inode_info *dst_zii = ZUII(dst_inode);
+	struct zus_inode *dst_zi = dst_zii->zi;
+	struct super_block *sb = src_inode->i_sb;
+	struct zufs_ioc_clone ioc_clone = {
+		.hdr.in_len = sizeof(ioc_clone),
+		.hdr.out_len = sizeof(ioc_clone),
+		.hdr.operation = operation,
+		.src_zus_ii = src_zii->zus_ii,
+		.dst_zus_ii = dst_zii->zus_ii,
+		.pos_in = pos_in,
+		.pos_out = pos_out,
+		.len = len,
+		.len_up = len_up,
+	};
+	int err;
+
+	/* NOTE: len==0 means to-end-of-file which is what we want */
+	unmap_mapping_range(src_inode->i_mapping, pos_in,  len, 0);
+	unmap_mapping_range(dst_inode->i_mapping, pos_out, len, 0);
+
+	zufc_goose_all_zts(ZUF_ROOT(SBI(dst_inode->i_sb)), NULL);
+
+	if ((len_up == 0) && (pos_in || pos_out)) {
+		zuf_err("Boaz Smoking 0x%llx 0x%llx 0x%llx\n",
+			pos_in, pos_out, len);
+		/* Bad caller */
+		return -EINVAL;
+	}
+
+	err = zufc_dispatch(ZUF_ROOT(SBI(sb)), &ioc_clone.hdr, NULL, 0);
+	if (unlikely(err && err != -EINTR)) {
+		zuf_dbg_err("failed to clone %ld -> %ld ; err=%d\n",
+			 src_inode->i_ino, dst_inode->i_ino, err);
+		return err;
+	}
+
+	dst_inode->i_blocks = le64_to_cpu(dst_zi->i_blocks);
+	i_size_write(dst_inode, dst_zi->i_size);
+
+	return err;
+}
+
+/* FIXME: Old checks are not needed. I keep them to make sure they
+ * are not complaining. Will remove _zuf_old_checks SOON
+ */
+static int _zuf_old_checks(struct super_block *sb,
+			   struct inode *src_inode, loff_t pos_in,
+			   struct inode *dst_inode, loff_t pos_out, loff_t len)
+{
+	if (src_inode == dst_inode) {
+		if (pos_in == pos_out) {
+			zuf_warn("[%ld] Clone nothing!!\n",
+				    src_inode->i_ino);
+			return 0;
+		}
+		if (pos_in < pos_out) {
+			if (pos_in + len > pos_out) {
+				zuf_warn("[%ld] overlapping pos_in < pos_out?? => EINVAL\n",
+					 src_inode->i_ino);
+				return -EINVAL;
+			}
+		} else {
+			if (pos_out + len > pos_in) {
+				zuf_warn("[%ld] overlapping pos_out < pos_in?? => EINVAL\n",
+					 src_inode->i_ino);
+				return -EINVAL;
+			}
+		}
+	}
+
+	if ((pos_in & (sb->s_blocksize - 1)) ||
+	    (pos_out & (sb->s_blocksize - 1))) {
+		zuf_err("[%ld] Not aligned len=0x%llx pos_in=0x%llx "
+			"pos_out=0x%llx src-size=0x%llx dst-size=0x%llx\n",
+			 src_inode->i_ino, len, pos_in, pos_out,
+			 i_size_read(src_inode), i_size_read(dst_inode));
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static loff_t zuf_clone_file_range(struct file *file_in, loff_t pos_in,
+				struct file *file_out, loff_t pos_out,
+				loff_t len, uint remap_flags)
+{
+	struct inode *src_inode = file_inode(file_in);
+	struct inode *dst_inode = file_inode(file_out);
+	struct zuf_inode_info *src_zii = ZUII(src_inode);
+	struct zuf_inode_info *dst_zii = ZUII(dst_inode);
+	ulong src_size = i_size_read(src_inode);
+	ulong dst_size = i_size_read(dst_inode);
+	struct super_block *sb = src_inode->i_sb;
+	ulong len_up;
+	int err;
+
+	zuf_dbg_vfs("IN: [%ld]{0x%llx} => [%ld]{0x%llx} length=0x%llx flags=0x%x\n",
+		    src_inode->i_ino, pos_in, dst_inode->i_ino, pos_out, len,
+		    remap_flags);
+
+	if (remap_flags & ~(REMAP_FILE_CAN_SHORTEN | REMAP_FILE_DEDUP)) {
+		/* New flags we do not know */
+		zuf_dbg_err("[%ld] Unknown remap_flags(0x%x)\n",
+			    src_inode->i_ino, remap_flags);
+		return -EINVAL;
+	}
+
+	if ((pos_in + len > sb->s_maxbytes) || (pos_out + len > sb->s_maxbytes))
+		return -EINVAL;
+
+	_lock_two_ziis(src_zii, dst_zii);
+
+	err = _remap_file_range_prep(file_in, pos_in, file_out, pos_out, &len,
+				     remap_flags);
+	if (err < 0 || len == 0)
+		goto out;
+	err = _zuf_old_checks(sb, src_inode, pos_in, dst_inode, pos_out, len);
+	if (unlikely(err))
+		goto out;
+
+	err = file_remove_privs(file_out);
+	if (unlikely(err))
+		goto out;
+
+	if (!(remap_flags & REMAP_FILE_DEDUP))
+		zus_inode_cmtime_now(dst_inode, dst_zii->zi);
+
+	/* See about all-file-clone optimization */
+	len_up = len;
+	if (!pos_in && !pos_out && (src_size <= pos_in + len) &&
+	    (dst_size <= src_size)) {
+		len_up = 0;
+	} else if (len & (sb->s_blocksize - 1)) {
+		/* un-aligned len, see if it is beyond EOF */
+		if ((src_size > pos_in  + len) ||
+		    (dst_size > pos_out + len)) {
+			zuf_err("[%ld][%ld] Not aligned len=0x%llx pos_in=0x%llx "
+				"pos_out=0x%llx src-size=0x%lx dst-size=0x%lx\n",
+				src_inode->i_ino, dst_inode->i_ino, len,
+				pos_in, pos_out, src_size, dst_size);
+			err = -EINVAL;
+			goto out;
+		}
+		len_up = md_p2o(md_o2p_up(len));
+	}
+
+	err = _clone_file_range(src_inode, pos_in, file_out, dst_inode, pos_out,
+				len, len_up, ZUFS_OP_CLONE);
+	if (unlikely(err))
+		zuf_dbg_err("_clone_file_range failed => %d\n", err);
+
+out:
+	_unlock_two_ziis(src_zii, dst_zii);
+	return err ? err : len;
+}
+
+static ssize_t zuf_copy_file_range(struct file *file_in, loff_t pos_in,
+				   struct file *file_out, loff_t pos_out,
+				   size_t len, uint flags)
+{
+	struct inode *src_inode = file_inode(file_in);
+	struct inode *dst_inode = file_inode(file_out);
+	ssize_t ret;
+
+	zuf_dbg_vfs("ino-in=%ld ino-out=%ld pos_in=0x%llx pos_out=0x%llx length=0x%lx\n",
+		    src_inode->i_ino, dst_inode->i_ino, pos_in, pos_out, len);
+
+	ret = zuf_clone_file_range(file_in, pos_in, file_out, pos_out, len,
+				   REMAP_FILE_ADVISORY);
+
+	return ret ?: len;
+}
+
+/* ZUFS:
+ * make sure we clean up the resources consumed by zufs_init()
+ */
+static int zuf_file_release(struct inode *inode, struct file *file)
+{
+	if (unlikely(file->private_data))
+		zuf_err("not yet\n");
+
+	/* FIXME: swapon code reads its header through the page cache.
+	 * So we clean it here. Need to submit a patch for reading swap
+	 * header through read_iter or direct_IO
+	 */
+	if (unlikely(file->f_mapping->nrpages)) {
+		zuf_dbg_err("Yes (%ld) swap=%d\n",
+			 file->f_mapping->nrpages, IS_SWAPFILE(inode));
+		truncate_inode_pages_range(file->f_mapping, 0,
+					file->f_mapping->nrpages << PAGE_SHIFT);
+	}
+
+	return 0;
+}
 
 ssize_t zuf_read_iter(struct kiocb *kiocb, struct iov_iter *ii)
 {
@@ -156,16 +790,44 @@ ssize_t zuf_write_iter(struct kiocb *kiocb, struct iov_iter *ii)
 	return ret;
 }
 
+static int zuf_fadvise(struct file *file, loff_t offset, loff_t len,
+		       int advise)
+{
+	struct inode *inode = file_inode(file);
+	struct zuf_inode_info *zii = ZUII(inode);
+	int err;
+
+	if (!S_ISREG(inode->i_mode))
+		return -EINVAL;
+
+	zuf_r_lock(zii);
+
+	err = zuf_rw_fadvise(inode->i_sb, inode, offset, len, advise,
+			     file->f_mode & FMODE_RANDOM);
+
+	zuf_r_unlock(zii);
+
+	return err;
+}
+
 const struct file_operations zuf_file_operations = {
 	.open			= generic_file_open,
 	.read_iter		= zuf_read_iter,
 	.write_iter		= zuf_write_iter,
 	.mmap			= zuf_file_mmap,
 	.fsync			= zuf_fsync,
+	.llseek			= zuf_llseek,
+	.flush			= zuf_flush,
+	.release		= zuf_file_release,
+	.fallocate		= zuf_fallocate,
+	.copy_file_range	= zuf_copy_file_range,
+	.remap_file_range	= zuf_clone_file_range,
+	.fadvise		= zuf_fadvise,
 };
 
 const struct inode_operations zuf_file_inode_operations = {
 	.setattr	= zuf_setattr,
 	.getattr	= zuf_getattr,
 	.update_time	= zuf_update_time,
+	.fiemap		= zuf_fiemap,
 };
fs/zuf/zuf-core.c +5 -0
index ff04c6912c17..9f690142f479 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.20.1
#24 lore raw

Re: [PATCH 13/16] zuf: More file operation

I love your patch! Perhaps something to improve:

Hi Boaz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to v5.3-rc4 next-20190813]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Boaz-Harrosh/zuf-ZUFS-Zero-copy-User-mode-FileSystem/20190813-074124
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

fs/zuf/file.c: In function 'zuf_fiemap':

>> fs/zuf/file.c:324:1: warning: the frame size of 8512 bytes is larger than 8192 bytes [-Wframe-larger-than=]
    }
    ^

vim +324 fs/zuf/file.c

243
244 static int zuf_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
245 u64 offset, u64 len)
246 {
247 struct super_block *sb = inode->i_sb;
248 struct zuf_inode_info *zii = ZUII(inode);
249 struct zufs_ioc_fiemap ioc_fiemap = {
250 .hdr.operation = ZUFS_OP_FIEMAP,
251 .hdr.in_len = sizeof(ioc_fiemap),
252 .hdr.out_len = sizeof(ioc_fiemap),
253 .zus_ii = zii->zus_ii,
254 .start = offset,
255 .length = len,
256 .flags = fieinfo->fi_flags,
257 };
258 struct page *pages[ZUS_API_MAP_MAX_PAGES];
259 uint nump = 0, extents_max = 0;
260 int i, err;
261
262 zuf_dbg_vfs("[%ld] offset=0x%llx len=0x%llx extents_max=%u flags=0x%x\n",
263 inode->i_ino, offset, len, fieinfo->fi_extents_max,
264 fieinfo->fi_flags);
265
266 /* TODO: Have support for FIEMAP_FLAG_XATTR */
267 err = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
268 if (unlikely(err))
269 return err;
270
271 if (likely(fieinfo->fi_extents_max)) {
272 ulong start = (ulong)fieinfo->fi_extents_start;
273 ulong len = fieinfo->fi_extents_max *
274 sizeof(struct fiemap_extent);
275 ulong offset = start & (PAGE_SIZE - 1);
276 ulong end_offset = (offset + len) & (PAGE_SIZE - 1);
277 ulong __len;
278 uint nump_r;
279
280 nump = md_o2p_up(offset + len);
281 if (ARRAY_SIZE(pages) < nump) {
282 nump = ARRAY_SIZE(pages);
283 end_offset = 0;
284 }
285
286 nump_r = get_user_pages_fast(start, nump, WRITE, pages);
287 if (unlikely(nump != nump_r))
288 return -EFAULT;
289
290 __len = nump * PAGE_SIZE - offset;
291 if (end_offset)
292 __len -= (PAGE_SIZE - end_offset);
293
294 extents_max = __len / sizeof(struct fiemap_extent);
295
296 ioc_fiemap.hdr.len = extents_max * sizeof(struct fiemap_extent);
297 ioc_fiemap.hdr.offset = offset;
298 }
299 ioc_fiemap.extents_max = extents_max;
300
301 zuf_r_lock(zii);
302
303 err = zufc_dispatch(ZUF_ROOT(SBI(sb)), &ioc_fiemap.hdr, pages, nump);
304 if (unlikely(err)) {
305 zuf_dbg_err("zufs_dispatch failed => %d\n", err);
306 goto out;
307 }
308
309 fieinfo->fi_extents_mapped = ioc_fiemap.extents_mapped;
310 if (unlikely(extents_max &&
311 (extents_max < ioc_fiemap.extents_mapped))) {
312 zuf_err("extents_max=%d extents_mapped=%d\n", extents_max,
313 ioc_fiemap.extents_mapped);
314 err = -EINVAL;
315 }
316
317 out:
318 zuf_r_unlock(zii);
319
320 for (i = 0; i < nump; ++i)
321 put_page(pages[i]);
322
323 return err;

 > 324	}

325

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#25 lore raw

PATCH 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)

---
 fs/zuf/Makefile    |   1 +
 fs/zuf/_extern.h   |   6 +
 fs/zuf/directory.c |   4 +
 fs/zuf/file.c      |   4 +
 fs/zuf/ioctl.c     | 313 +++++++++++++++++++++++++++++++++++++++++++++
 fs/zuf/zuf-core.c  |   1 +
 fs/zuf/zus_api.h   |  37 ++++++
 7 files changed, 366 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 34fde591cf92..ec9a8f1fdd16 100644
@@ -127,6 +127,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 645dd367fd8c..11fcbe0ba6ff 100644
@@ -160,4 +160,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 b7657e8c7e0a..bde5b95c911c 100644
@@ -823,6 +823,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 +313 -0

313 lines not on this page · raw message

fs/zuf/zuf-core.c +1 -0
index 9f690142f479..b90c9efcb042 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 1a7b53157192..ce5ae0150b22 100644
@@ -470,6 +470,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,
@@ -712,6 +713,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.20.1
#26 lore raw

PATCH 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      |  35 ++++++
 fs/zuf/zus_api.h  |  23 ++++
 12 files changed, 696 insertions(+), 1 deletion(-)
 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 ec9a8f1fdd16..6ede8e509b9f 100644
@@ -133,6 +133,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 bde5b95c911c..f53490ae4377 100644
@@ -834,4 +834,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 567fb4117371..f207f5749b16 100644
@@ -291,12 +291,14 @@ 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 */
 
 		zuf_evict_dispatch(sb, zii->zus_ii, ZUFS_OP_FREE_INODE, 0);
 
 		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 91586b92099a..fd714b849c26 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);
@@ -842,6 +843,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 b90c9efcb042..7c2990624b9f 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 +35 -0
index e78515d7a3fe..ab96d012bd3d 100644
@@ -129,6 +129,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,39 @@ static inline void ZUF_CHECK_I_W_LOCK(struct inode *inode)
 #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;
+} __packed;
+
 enum big_alloc_type { ba_stack, ba_kmalloc, ba_vmalloc };
 
 static inline
fs/zuf/zus_api.h +23 -0
index ce5ae0150b22..cd4183d27232 100644
@@ -471,6 +471,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,
@@ -749,6 +752,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];
+} __packed;
+
+
 /* ZUFS_OP_FIEMAP */
 struct zufs_ioc_fiemap {
 	struct zufs_ioc_hdr hdr;
Signature · 1 line
2.20.1
#27 lore raw

PATCH 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 6ede8e509b9f..883f1465752b 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.20.1