pykvfs 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pykvfs-0.1.1/LICENSE +201 -0
- pykvfs-0.1.1/PKG-INFO +62 -0
- pykvfs-0.1.1/README.md +43 -0
- pykvfs-0.1.1/kvfs.py +510 -0
- pykvfs-0.1.1/pykvfs.egg-info/PKG-INFO +62 -0
- pykvfs-0.1.1/pykvfs.egg-info/SOURCES.txt +10 -0
- pykvfs-0.1.1/pykvfs.egg-info/dependency_links.txt +1 -0
- pykvfs-0.1.1/pykvfs.egg-info/entry_points.txt +2 -0
- pykvfs-0.1.1/pykvfs.egg-info/requires.txt +3 -0
- pykvfs-0.1.1/pykvfs.egg-info/top_level.txt +1 -0
- pykvfs-0.1.1/pyproject.toml +37 -0
- pykvfs-0.1.1/setup.cfg +4 -0
pykvfs-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
pykvfs-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pykvfs
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Redis/Valkey backed FUSE filesystem
|
|
5
|
+
Author: Muayyad Alsadi
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/muayyad-alsadi/pykvfs
|
|
8
|
+
Project-URL: Repository, https://github.com/muayyad-alsadi/pykvfs
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Topic :: System :: Filesystems
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: pyfuse3
|
|
16
|
+
Requires-Dist: redis[hiredis]
|
|
17
|
+
Requires-Dist: trio
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# kvfs
|
|
21
|
+
Simple networked filesystem backed by `redis` or `valkey`
|
|
22
|
+
|
|
23
|
+
It's intended for small files (like config files, `.env`, ..etc.).
|
|
24
|
+
Because redis/valkey is in-memory.
|
|
25
|
+
|
|
26
|
+
This project uses `fuse3` and `asyncio`
|
|
27
|
+
|
|
28
|
+
see [PyPI: kvfs-fuse](https://pypi.org/project/kvfs-fuse/)
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install kvfs-fuse
|
|
34
|
+
mkdir ~/kvfs_mnt
|
|
35
|
+
kvfs ~/kvfs_mnt
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
you can specify ip, port, db number, and prefix like this
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
kvfs --redis-url='redis://1.2.3.4:6379/0' --prefix='kvfs' ~/kvfs_mnt
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
you can mount it on multiple machines, so that when you edit the config files or `.env`
|
|
45
|
+
they will be updated on all of your machines
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Dependencies
|
|
49
|
+
|
|
50
|
+
you need `redis` and `pyfuse3`
|
|
51
|
+
which might need python development and fuse3 development
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
dnf install -y python3-devel fuse3-devel
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## How does it work
|
|
58
|
+
|
|
59
|
+
- `kvfs:meta:/path/to/file` stores the meta data of your file
|
|
60
|
+
- `kvfs:data:/path/to/file` stores the actual content
|
|
61
|
+
- `kvfs:dir:/path/to/dir/` stores the dir entry
|
|
62
|
+
|
pykvfs-0.1.1/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# kvfs
|
|
2
|
+
Simple networked filesystem backed by `redis` or `valkey`
|
|
3
|
+
|
|
4
|
+
It's intended for small files (like config files, `.env`, ..etc.).
|
|
5
|
+
Because redis/valkey is in-memory.
|
|
6
|
+
|
|
7
|
+
This project uses `fuse3` and `asyncio`
|
|
8
|
+
|
|
9
|
+
see [PyPI: kvfs-fuse](https://pypi.org/project/kvfs-fuse/)
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
pip install kvfs-fuse
|
|
15
|
+
mkdir ~/kvfs_mnt
|
|
16
|
+
kvfs ~/kvfs_mnt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
you can specify ip, port, db number, and prefix like this
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
kvfs --redis-url='redis://1.2.3.4:6379/0' --prefix='kvfs' ~/kvfs_mnt
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
you can mount it on multiple machines, so that when you edit the config files or `.env`
|
|
26
|
+
they will be updated on all of your machines
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Dependencies
|
|
30
|
+
|
|
31
|
+
you need `redis` and `pyfuse3`
|
|
32
|
+
which might need python development and fuse3 development
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
dnf install -y python3-devel fuse3-devel
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## How does it work
|
|
39
|
+
|
|
40
|
+
- `kvfs:meta:/path/to/file` stores the meta data of your file
|
|
41
|
+
- `kvfs:data:/path/to/file` stores the actual content
|
|
42
|
+
- `kvfs:dir:/path/to/dir/` stores the dir entry
|
|
43
|
+
|
pykvfs-0.1.1/kvfs.py
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
import asyncio
|
|
4
|
+
import errno
|
|
5
|
+
import os
|
|
6
|
+
import stat
|
|
7
|
+
import time
|
|
8
|
+
|
|
9
|
+
import pyfuse3
|
|
10
|
+
import pyfuse3.asyncio
|
|
11
|
+
from redis import asyncio as aioredis
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
META_FIELDS = ("type", "mode", "uid", "gid", "size", "atime_ns", "mtime_ns",
|
|
15
|
+
"ctime_ns", "nlink", "ino", "version")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def now_ns():
|
|
19
|
+
return time.time_ns()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def norm(path: str) -> str:
|
|
23
|
+
path = os.path.normpath(path or "/")
|
|
24
|
+
if not path.startswith("/"):
|
|
25
|
+
path = "/" + path
|
|
26
|
+
return path
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def split_parent(path: str):
|
|
30
|
+
path = norm(path)
|
|
31
|
+
if path == "/":
|
|
32
|
+
return "/", ""
|
|
33
|
+
return os.path.dirname(path) or "/", os.path.basename(path)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class KVFS(pyfuse3.Operations):
|
|
37
|
+
supports_dot_lookup = True
|
|
38
|
+
enable_writeback_cache = False
|
|
39
|
+
|
|
40
|
+
def __init__(self, redis_url, entry_timeout=0.25, attr_timeout=0.25,
|
|
41
|
+
waitaof=False, wait_timeout_ms=5000, prefix="kvfs"):
|
|
42
|
+
super().__init__()
|
|
43
|
+
self.redis = aioredis.from_url(redis_url)
|
|
44
|
+
self.prefix = prefix
|
|
45
|
+
self.entry_timeout = entry_timeout
|
|
46
|
+
self.attr_timeout = attr_timeout
|
|
47
|
+
self.waitaof = waitaof
|
|
48
|
+
self.wait_timeout_ms = wait_timeout_ms
|
|
49
|
+
|
|
50
|
+
self.path_to_ino = {"/": pyfuse3.ROOT_INODE}
|
|
51
|
+
self.ino_to_path = {pyfuse3.ROOT_INODE: "/"}
|
|
52
|
+
self.lookup_count = {pyfuse3.ROOT_INODE: 1}
|
|
53
|
+
|
|
54
|
+
self.dir_handles = {}
|
|
55
|
+
self.open_files = {} # fh -> {"path","buf","dirty","lock"}
|
|
56
|
+
self.next_fh = 100
|
|
57
|
+
self.lock_guard = asyncio.Lock()
|
|
58
|
+
self.path_locks = {}
|
|
59
|
+
|
|
60
|
+
def _meta_key(self, path): return f"{self.prefix}:meta:{norm(path)}"
|
|
61
|
+
def _data_key(self, path): return f"{self.prefix}:data:{norm(path)}"
|
|
62
|
+
def _dir_key(self, path): return f"{self.prefix}:dir:{norm(path)}"
|
|
63
|
+
|
|
64
|
+
async def _ensure_root(self):
|
|
65
|
+
if await self.redis.exists(self._meta_key("/")):
|
|
66
|
+
return
|
|
67
|
+
t = now_ns()
|
|
68
|
+
root = {
|
|
69
|
+
"type": "dir",
|
|
70
|
+
"mode": stat.S_IFDIR | 0o755,
|
|
71
|
+
"uid": os.getuid(),
|
|
72
|
+
"gid": os.getgid(),
|
|
73
|
+
"size": 0,
|
|
74
|
+
"atime_ns": t,
|
|
75
|
+
"mtime_ns": t,
|
|
76
|
+
"ctime_ns": t,
|
|
77
|
+
"nlink": 2,
|
|
78
|
+
"ino": int(pyfuse3.ROOT_INODE),
|
|
79
|
+
"version": 1,
|
|
80
|
+
}
|
|
81
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
82
|
+
await pipe.hset(self._meta_key("/"), mapping=root)
|
|
83
|
+
await pipe.delete(self._dir_key("/"))
|
|
84
|
+
await pipe.execute()
|
|
85
|
+
|
|
86
|
+
async def _path_lock(self, path):
|
|
87
|
+
path = norm(path)
|
|
88
|
+
async with self.lock_guard:
|
|
89
|
+
if path not in self.path_locks:
|
|
90
|
+
self.path_locks[path] = asyncio.Lock()
|
|
91
|
+
return self.path_locks[path]
|
|
92
|
+
|
|
93
|
+
async def _get_meta(self, path):
|
|
94
|
+
row = await self.redis.hmget(self._meta_key(path), *META_FIELDS)
|
|
95
|
+
if not row or row[0] is None:
|
|
96
|
+
return None
|
|
97
|
+
vals = {k: row[i] for i, k in enumerate(META_FIELDS)}
|
|
98
|
+
return {
|
|
99
|
+
"path": norm(path),
|
|
100
|
+
"type": vals["type"].decode() if isinstance(vals["type"], (bytes, bytearray)) else vals["type"],
|
|
101
|
+
"mode": int(vals["mode"]),
|
|
102
|
+
"uid": int(vals["uid"]),
|
|
103
|
+
"gid": int(vals["gid"]),
|
|
104
|
+
"size": int(vals["size"]),
|
|
105
|
+
"atime_ns": int(vals["atime_ns"]),
|
|
106
|
+
"mtime_ns": int(vals["mtime_ns"]),
|
|
107
|
+
"ctime_ns": int(vals["ctime_ns"]),
|
|
108
|
+
"nlink": int(vals["nlink"]),
|
|
109
|
+
"ino": int(vals["ino"]),
|
|
110
|
+
"version": int(vals["version"]),
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
def _mapping(self, m):
|
|
114
|
+
return {k: int(v) if isinstance(v, bool) or isinstance(v, int) else v
|
|
115
|
+
for k, v in m.items() if k != "path"}
|
|
116
|
+
|
|
117
|
+
def _entry(self, m):
|
|
118
|
+
e = pyfuse3.EntryAttributes()
|
|
119
|
+
e.st_ino = int(m["ino"])
|
|
120
|
+
e.st_mode = int(m["mode"])
|
|
121
|
+
e.st_uid = int(m["uid"])
|
|
122
|
+
e.st_gid = int(m["gid"])
|
|
123
|
+
e.st_nlink = int(m["nlink"])
|
|
124
|
+
e.st_size = int(m["size"])
|
|
125
|
+
e.st_atime_ns = int(m["atime_ns"])
|
|
126
|
+
e.st_mtime_ns = int(m["mtime_ns"])
|
|
127
|
+
e.st_ctime_ns = int(m["ctime_ns"])
|
|
128
|
+
e.st_blksize = 4096
|
|
129
|
+
e.st_blocks = (int(m["size"]) + 511) // 512
|
|
130
|
+
e.attr_timeout = self.attr_timeout
|
|
131
|
+
e.entry_timeout = self.entry_timeout
|
|
132
|
+
return e
|
|
133
|
+
|
|
134
|
+
def _remember(self, path, ino):
|
|
135
|
+
path = norm(path)
|
|
136
|
+
self.path_to_ino[path] = int(ino)
|
|
137
|
+
self.ino_to_path[int(ino)] = path
|
|
138
|
+
self.lookup_count[int(ino)] = self.lookup_count.get(int(ino), 0)
|
|
139
|
+
|
|
140
|
+
async def _child_path(self, parent_inode, name: bytes):
|
|
141
|
+
parent = self.ino_to_path.get(int(parent_inode))
|
|
142
|
+
if parent is None:
|
|
143
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
144
|
+
text = os.fsdecode(name)
|
|
145
|
+
if text == ".":
|
|
146
|
+
return parent
|
|
147
|
+
if text == "..":
|
|
148
|
+
return "/" if parent == "/" else os.path.dirname(parent) or "/"
|
|
149
|
+
return norm(os.path.join(parent, text))
|
|
150
|
+
|
|
151
|
+
async def _alloc_fh(self, path):
|
|
152
|
+
self.next_fh += 1
|
|
153
|
+
fh = self.next_fh
|
|
154
|
+
self.open_files[fh] = {"path": norm(path), "buf": None, "dirty": False, "lock": asyncio.Lock()}
|
|
155
|
+
return fh
|
|
156
|
+
|
|
157
|
+
async def _load_buf(self, fh):
|
|
158
|
+
h = self.open_files[fh]
|
|
159
|
+
if h["buf"] is None:
|
|
160
|
+
blob = await self.redis.get(self._data_key(h["path"])) or b""
|
|
161
|
+
h["buf"] = bytearray(blob)
|
|
162
|
+
|
|
163
|
+
async def _flush_fh(self, fh, datasync=False):
|
|
164
|
+
h = self.open_files[fh]
|
|
165
|
+
async with h["lock"]:
|
|
166
|
+
if not h["dirty"]:
|
|
167
|
+
if self.waitaof:
|
|
168
|
+
try:
|
|
169
|
+
await self.redis.execute_command("WAITAOF", 1, 0, self.wait_timeout_ms)
|
|
170
|
+
except Exception:
|
|
171
|
+
pass
|
|
172
|
+
return
|
|
173
|
+
meta = await self._get_meta(h["path"])
|
|
174
|
+
if meta is None:
|
|
175
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
176
|
+
payload = bytes(h["buf"] or b"")
|
|
177
|
+
t = now_ns()
|
|
178
|
+
meta["size"] = len(payload)
|
|
179
|
+
meta["mtime_ns"] = t
|
|
180
|
+
meta["atime_ns"] = t
|
|
181
|
+
if not datasync:
|
|
182
|
+
meta["ctime_ns"] = t
|
|
183
|
+
meta["version"] += 1
|
|
184
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
185
|
+
await pipe.set(self._data_key(h["path"]), payload)
|
|
186
|
+
await pipe.hset(self._meta_key(h["path"]), mapping=self._mapping(meta))
|
|
187
|
+
await pipe.execute()
|
|
188
|
+
h["dirty"] = False
|
|
189
|
+
if self.waitaof:
|
|
190
|
+
try:
|
|
191
|
+
await self.redis.execute_command("WAITAOF", 1, 0, self.wait_timeout_ms)
|
|
192
|
+
except Exception:
|
|
193
|
+
pass
|
|
194
|
+
|
|
195
|
+
async def init(self):
|
|
196
|
+
await self._ensure_root()
|
|
197
|
+
|
|
198
|
+
async def lookup(self, parent_inode, name, ctx=None):
|
|
199
|
+
path = await self._child_path(parent_inode, name)
|
|
200
|
+
m = await self._get_meta(path)
|
|
201
|
+
if m is None:
|
|
202
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
203
|
+
self._remember(path, m["ino"])
|
|
204
|
+
self.lookup_count[m["ino"]] = self.lookup_count.get(m["ino"], 0) + 1
|
|
205
|
+
return self._entry(m)
|
|
206
|
+
|
|
207
|
+
async def getattr(self, inode, ctx=None):
|
|
208
|
+
path = self.ino_to_path.get(int(inode))
|
|
209
|
+
if path is None:
|
|
210
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
211
|
+
m = await self._get_meta(path)
|
|
212
|
+
if m is None:
|
|
213
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
214
|
+
return self._entry(m)
|
|
215
|
+
|
|
216
|
+
async def opendir(self, inode, ctx):
|
|
217
|
+
if int(inode) not in self.ino_to_path:
|
|
218
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
219
|
+
self.next_fh += 1
|
|
220
|
+
fh = self.next_fh
|
|
221
|
+
self.dir_handles[fh] = self.ino_to_path[int(inode)]
|
|
222
|
+
return fh
|
|
223
|
+
|
|
224
|
+
async def readdir(self, fh, start_id, token):
|
|
225
|
+
path = self.dir_handles[fh]
|
|
226
|
+
names = await self.redis.smembers(self._dir_key(path))
|
|
227
|
+
names = sorted(os.fsdecode(n) if isinstance(n, (bytes, bytearray)) else n for n in names)
|
|
228
|
+
|
|
229
|
+
pipe = self.redis.pipeline(transaction=False)
|
|
230
|
+
child_paths = []
|
|
231
|
+
for name in names:
|
|
232
|
+
child = norm(os.path.join(path, name))
|
|
233
|
+
child_paths.append((name, child))
|
|
234
|
+
pipe.hmget(self._meta_key(child), *META_FIELDS)
|
|
235
|
+
rows = await pipe.execute()
|
|
236
|
+
|
|
237
|
+
entries = []
|
|
238
|
+
for (name, child), row in zip(child_paths, rows):
|
|
239
|
+
if not row or row[0] is None:
|
|
240
|
+
continue
|
|
241
|
+
m = {
|
|
242
|
+
"path": child,
|
|
243
|
+
"type": row[0].decode() if isinstance(row[0], (bytes, bytearray)) else row[0],
|
|
244
|
+
"mode": int(row[1]), "uid": int(row[2]), "gid": int(row[3]),
|
|
245
|
+
"size": int(row[4]), "atime_ns": int(row[5]), "mtime_ns": int(row[6]),
|
|
246
|
+
"ctime_ns": int(row[7]), "nlink": int(row[8]), "ino": int(row[9]),
|
|
247
|
+
"version": int(row[10]),
|
|
248
|
+
}
|
|
249
|
+
entries.append((m["ino"], name, self._entry(m), child))
|
|
250
|
+
|
|
251
|
+
entries.sort(key=lambda x: x[0])
|
|
252
|
+
for ino, name, attr, child in entries:
|
|
253
|
+
if ino <= start_id:
|
|
254
|
+
continue
|
|
255
|
+
ok = pyfuse3.readdir_reply(token, os.fsencode(name), attr, ino)
|
|
256
|
+
if not ok:
|
|
257
|
+
return
|
|
258
|
+
self._remember(child, ino)
|
|
259
|
+
self.lookup_count[ino] = self.lookup_count.get(ino, 0) + 1
|
|
260
|
+
|
|
261
|
+
async def open(self, inode, flags, ctx):
|
|
262
|
+
path = self.ino_to_path.get(int(inode))
|
|
263
|
+
if path is None:
|
|
264
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
265
|
+
fh = await self._alloc_fh(path)
|
|
266
|
+
return pyfuse3.FileInfo(fh=fh)
|
|
267
|
+
|
|
268
|
+
async def read(self, fh, off, size):
|
|
269
|
+
h = self.open_files[fh]
|
|
270
|
+
async with h["lock"]:
|
|
271
|
+
if h["buf"] is not None:
|
|
272
|
+
return bytes(h["buf"][off:off + size])
|
|
273
|
+
return await self.redis.getrange(self._data_key(h["path"]), off, off + size - 1) or b""
|
|
274
|
+
|
|
275
|
+
async def write(self, fh, off, buf):
|
|
276
|
+
h = self.open_files[fh]
|
|
277
|
+
async with h["lock"]:
|
|
278
|
+
await self._load_buf(fh)
|
|
279
|
+
end = off + len(buf)
|
|
280
|
+
if end > len(h["buf"]):
|
|
281
|
+
h["buf"].extend(b"\x00" * (end - len(h["buf"])))
|
|
282
|
+
h["buf"][off:end] = buf
|
|
283
|
+
h["dirty"] = True
|
|
284
|
+
return len(buf)
|
|
285
|
+
|
|
286
|
+
async def create(self, parent_inode, name, mode, flags, ctx):
|
|
287
|
+
parent = self.ino_to_path.get(int(parent_inode))
|
|
288
|
+
if parent is None:
|
|
289
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
290
|
+
path = norm(os.path.join(parent, os.fsdecode(name)))
|
|
291
|
+
lock_a = await self._path_lock(parent)
|
|
292
|
+
lock_b = await self._path_lock(path)
|
|
293
|
+
async with lock_a, lock_b:
|
|
294
|
+
if await self.redis.exists(self._meta_key(path)):
|
|
295
|
+
raise pyfuse3.FUSEError(errno.EEXIST)
|
|
296
|
+
ino = abs(hash((path, now_ns()))) & ((1 << 63) - 1) or 2
|
|
297
|
+
t = now_ns()
|
|
298
|
+
meta = {
|
|
299
|
+
"type": "file",
|
|
300
|
+
"mode": int(stat.S_IFREG | mode),
|
|
301
|
+
"uid": int(ctx.uid),
|
|
302
|
+
"gid": int(ctx.gid),
|
|
303
|
+
"size": 0,
|
|
304
|
+
"atime_ns": t, "mtime_ns": t, "ctime_ns": t,
|
|
305
|
+
"nlink": 1, "ino": ino, "version": 1
|
|
306
|
+
}
|
|
307
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
308
|
+
await pipe.hset(self._meta_key(path), mapping=meta)
|
|
309
|
+
await pipe.set(self._data_key(path), b"")
|
|
310
|
+
await pipe.sadd(self._dir_key(parent), os.fsdecode(name))
|
|
311
|
+
await pipe.execute()
|
|
312
|
+
self._remember(path, ino)
|
|
313
|
+
self.lookup_count[ino] = self.lookup_count.get(ino, 0) + 1
|
|
314
|
+
fh = await self._alloc_fh(path)
|
|
315
|
+
return pyfuse3.FileInfo(fh=fh), self._entry({**meta, "path": path})
|
|
316
|
+
|
|
317
|
+
async def unlink(self, parent_inode, name, ctx):
|
|
318
|
+
parent = self.ino_to_path.get(int(parent_inode))
|
|
319
|
+
path = norm(os.path.join(parent, os.fsdecode(name)))
|
|
320
|
+
lock_a = await self._path_lock(parent)
|
|
321
|
+
lock_b = await self._path_lock(path)
|
|
322
|
+
async with lock_a, lock_b:
|
|
323
|
+
m = await self._get_meta(path)
|
|
324
|
+
if m is None:
|
|
325
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
326
|
+
if m["type"] != "file":
|
|
327
|
+
raise pyfuse3.FUSEError(errno.EISDIR)
|
|
328
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
329
|
+
await pipe.delete(self._meta_key(path))
|
|
330
|
+
await pipe.delete(self._data_key(path))
|
|
331
|
+
await pipe.srem(self._dir_key(parent), os.fsdecode(name))
|
|
332
|
+
await pipe.execute()
|
|
333
|
+
self.path_to_ino.pop(path, None)
|
|
334
|
+
|
|
335
|
+
async def mkdir(self, parent_inode, name, mode, ctx):
|
|
336
|
+
parent = self.ino_to_path.get(int(parent_inode))
|
|
337
|
+
path = norm(os.path.join(parent, os.fsdecode(name)))
|
|
338
|
+
ino = abs(hash((path, now_ns()))) & ((1 << 63) - 1) or 2
|
|
339
|
+
t = now_ns()
|
|
340
|
+
meta = {
|
|
341
|
+
"type": "dir",
|
|
342
|
+
"mode": int(stat.S_IFDIR | mode),
|
|
343
|
+
"uid": int(ctx.uid),
|
|
344
|
+
"gid": int(ctx.gid),
|
|
345
|
+
"size": 0,
|
|
346
|
+
"atime_ns": t, "mtime_ns": t, "ctime_ns": t,
|
|
347
|
+
"nlink": 2, "ino": ino, "version": 1
|
|
348
|
+
}
|
|
349
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
350
|
+
await pipe.hset(self._meta_key(path), mapping=meta)
|
|
351
|
+
await pipe.delete(self._dir_key(path))
|
|
352
|
+
await pipe.sadd(self._dir_key(parent), os.fsdecode(name))
|
|
353
|
+
await pipe.execute()
|
|
354
|
+
self._remember(path, ino)
|
|
355
|
+
self.lookup_count[ino] = self.lookup_count.get(ino, 0) + 1
|
|
356
|
+
return self._entry({**meta, "path": path})
|
|
357
|
+
|
|
358
|
+
async def rmdir(self, parent_inode, name, ctx):
|
|
359
|
+
parent = self.ino_to_path.get(int(parent_inode))
|
|
360
|
+
path = norm(os.path.join(parent, os.fsdecode(name)))
|
|
361
|
+
if await self.redis.scard(self._dir_key(path)) != 0:
|
|
362
|
+
raise pyfuse3.FUSEError(errno.ENOTEMPTY)
|
|
363
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
364
|
+
await pipe.delete(self._meta_key(path))
|
|
365
|
+
await pipe.delete(self._dir_key(path))
|
|
366
|
+
await pipe.srem(self._dir_key(parent), os.fsdecode(name))
|
|
367
|
+
await pipe.execute()
|
|
368
|
+
self.path_to_ino.pop(path, None)
|
|
369
|
+
|
|
370
|
+
async def rename(self, parent_inode_old, name_old, parent_inode_new, name_new, flags, ctx):
|
|
371
|
+
old_parent = self.ino_to_path.get(int(parent_inode_old))
|
|
372
|
+
new_parent = self.ino_to_path.get(int(parent_inode_new))
|
|
373
|
+
old = norm(os.path.join(old_parent, os.fsdecode(name_old)))
|
|
374
|
+
new = norm(os.path.join(new_parent, os.fsdecode(name_new)))
|
|
375
|
+
if old == new:
|
|
376
|
+
return
|
|
377
|
+
src = await self._get_meta(old)
|
|
378
|
+
if src is None:
|
|
379
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
380
|
+
dst = await self._get_meta(new)
|
|
381
|
+
|
|
382
|
+
if src["type"] == "dir" and await self.redis.scard(self._dir_key(old)) != 0:
|
|
383
|
+
raise pyfuse3.FUSEError(errno.ENOTSUP)
|
|
384
|
+
|
|
385
|
+
if flags & pyfuse3.RENAME_NOREPLACE and dst is not None:
|
|
386
|
+
raise pyfuse3.FUSEError(errno.EEXIST)
|
|
387
|
+
if flags & pyfuse3.RENAME_EXCHANGE:
|
|
388
|
+
raise pyfuse3.FUSEError(errno.ENOTSUP)
|
|
389
|
+
|
|
390
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
391
|
+
await pipe.rename(self._meta_key(old), self._meta_key(new))
|
|
392
|
+
if src["type"] == "file" and await self.redis.exists(self._data_key(old)):
|
|
393
|
+
await pipe.rename(self._data_key(old), self._data_key(new))
|
|
394
|
+
if src["type"] == "dir":
|
|
395
|
+
await pipe.rename(self._dir_key(old), self._dir_key(new))
|
|
396
|
+
await pipe.srem(self._dir_key(old_parent), os.fsdecode(name_old))
|
|
397
|
+
await pipe.sadd(self._dir_key(new_parent), os.fsdecode(name_new))
|
|
398
|
+
await pipe.execute()
|
|
399
|
+
|
|
400
|
+
ino = src["ino"]
|
|
401
|
+
self.path_to_ino.pop(old, None)
|
|
402
|
+
self._remember(new, ino)
|
|
403
|
+
|
|
404
|
+
async def setattr(self, inode, attr, fields, fh, ctx):
|
|
405
|
+
"""
|
|
406
|
+
In pyfuse3 this handles both truncate and utimens.
|
|
407
|
+
"""
|
|
408
|
+
path = self.ino_to_path.get(int(inode))
|
|
409
|
+
if path is None:
|
|
410
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
411
|
+
meta = await self._get_meta(path)
|
|
412
|
+
if meta is None:
|
|
413
|
+
raise pyfuse3.FUSEError(errno.ENOENT)
|
|
414
|
+
|
|
415
|
+
if fields.update_size:
|
|
416
|
+
if fh is not None and fh in self.open_files:
|
|
417
|
+
h = self.open_files[fh]
|
|
418
|
+
async with h["lock"]:
|
|
419
|
+
await self._load_buf(fh)
|
|
420
|
+
h["buf"] = h["buf"][:attr.st_size].ljust(attr.st_size, b"\x00")
|
|
421
|
+
h["dirty"] = True
|
|
422
|
+
else:
|
|
423
|
+
blob = await self.redis.get(self._data_key(path)) or b""
|
|
424
|
+
blob = blob[:attr.st_size].ljust(attr.st_size, b"\x00")
|
|
425
|
+
meta["size"] = int(attr.st_size)
|
|
426
|
+
meta["mtime_ns"] = meta["ctime_ns"] = now_ns()
|
|
427
|
+
meta["version"] += 1
|
|
428
|
+
async with self.redis.pipeline(transaction=True) as pipe:
|
|
429
|
+
await pipe.set(self._data_key(path), blob)
|
|
430
|
+
await pipe.hset(self._meta_key(path), mapping=self._mapping(meta))
|
|
431
|
+
await pipe.execute()
|
|
432
|
+
|
|
433
|
+
if fields.update_atime:
|
|
434
|
+
meta["atime_ns"] = int(attr.st_atime_ns)
|
|
435
|
+
if fields.update_mtime:
|
|
436
|
+
meta["mtime_ns"] = int(attr.st_mtime_ns)
|
|
437
|
+
if fields.update_atime or fields.update_mtime:
|
|
438
|
+
meta["ctime_ns"] = now_ns()
|
|
439
|
+
meta["version"] += 1
|
|
440
|
+
await self.redis.hset(self._meta_key(path), mapping=self._mapping(meta))
|
|
441
|
+
|
|
442
|
+
return await self.getattr(inode, ctx)
|
|
443
|
+
|
|
444
|
+
async def flush(self, fh):
|
|
445
|
+
await self._flush_fh(fh, False)
|
|
446
|
+
|
|
447
|
+
async def fsync(self, fh, datasync):
|
|
448
|
+
await self._flush_fh(fh, bool(datasync))
|
|
449
|
+
|
|
450
|
+
async def release(self, fh):
|
|
451
|
+
try:
|
|
452
|
+
await self._flush_fh(fh, False)
|
|
453
|
+
finally:
|
|
454
|
+
self.open_files.pop(fh, None)
|
|
455
|
+
|
|
456
|
+
async def fsyncdir(self, fh, datasync):
|
|
457
|
+
return
|
|
458
|
+
|
|
459
|
+
async def releasedir(self, fh):
|
|
460
|
+
self.dir_handles.pop(fh, None)
|
|
461
|
+
|
|
462
|
+
async def forget(self, inode_list):
|
|
463
|
+
for ino, nlookup in inode_list:
|
|
464
|
+
ino = int(ino)
|
|
465
|
+
self.lookup_count[ino] = self.lookup_count.get(ino, 0) - int(nlookup)
|
|
466
|
+
if self.lookup_count[ino] <= 0 and ino != pyfuse3.ROOT_INODE:
|
|
467
|
+
path = self.ino_to_path.pop(ino, None)
|
|
468
|
+
if path:
|
|
469
|
+
self.path_to_ino.pop(path, None)
|
|
470
|
+
self.lookup_count.pop(ino, None)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
async def main_async(args):
|
|
474
|
+
pyfuse3.asyncio.enable()
|
|
475
|
+
ops = KVFS(
|
|
476
|
+
redis_url=args.redis_url,
|
|
477
|
+
entry_timeout=args.entry_timeout,
|
|
478
|
+
attr_timeout=args.attr_timeout,
|
|
479
|
+
waitaof=args.waitaof,
|
|
480
|
+
prefix=args.prefix,
|
|
481
|
+
)
|
|
482
|
+
fuse_options = set(pyfuse3.default_options)
|
|
483
|
+
fuse_options.add("fsname=kvfs")
|
|
484
|
+
fuse_options.add("default_permissions")
|
|
485
|
+
#fuse_options.add(f"entry_timeout={args.entry_timeout}")
|
|
486
|
+
#fuse_options.add(f"attr_timeout={args.attr_timeout}")
|
|
487
|
+
#fuse_options.add("negative_timeout=0")
|
|
488
|
+
pyfuse3.init(ops, args.mountpoint, fuse_options)
|
|
489
|
+
try:
|
|
490
|
+
await ops.init()
|
|
491
|
+
await pyfuse3.main()
|
|
492
|
+
finally:
|
|
493
|
+
pyfuse3.close()
|
|
494
|
+
await ops.redis.aclose()
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def main():
|
|
498
|
+
ap = argparse.ArgumentParser()
|
|
499
|
+
ap.add_argument("mountpoint")
|
|
500
|
+
ap.add_argument("--redis-url", default="redis://127.0.0.1:6379/0")
|
|
501
|
+
ap.add_argument("--prefix", default="kvfs")
|
|
502
|
+
ap.add_argument("--entry-timeout", type=float, default=0.25)
|
|
503
|
+
ap.add_argument("--attr-timeout", type=float, default=0.25)
|
|
504
|
+
ap.add_argument("--waitaof", action="store_true")
|
|
505
|
+
args = ap.parse_args()
|
|
506
|
+
asyncio.run(main_async(args))
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
if __name__ == "__main__":
|
|
510
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pykvfs
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Redis/Valkey backed FUSE filesystem
|
|
5
|
+
Author: Muayyad Alsadi
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/muayyad-alsadi/pykvfs
|
|
8
|
+
Project-URL: Repository, https://github.com/muayyad-alsadi/pykvfs
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Topic :: System :: Filesystems
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: pyfuse3
|
|
16
|
+
Requires-Dist: redis[hiredis]
|
|
17
|
+
Requires-Dist: trio
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# kvfs
|
|
21
|
+
Simple networked filesystem backed by `redis` or `valkey`
|
|
22
|
+
|
|
23
|
+
It's intended for small files (like config files, `.env`, ..etc.).
|
|
24
|
+
Because redis/valkey is in-memory.
|
|
25
|
+
|
|
26
|
+
This project uses `fuse3` and `asyncio`
|
|
27
|
+
|
|
28
|
+
see [PyPI: kvfs-fuse](https://pypi.org/project/kvfs-fuse/)
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install kvfs-fuse
|
|
34
|
+
mkdir ~/kvfs_mnt
|
|
35
|
+
kvfs ~/kvfs_mnt
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
you can specify ip, port, db number, and prefix like this
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
kvfs --redis-url='redis://1.2.3.4:6379/0' --prefix='kvfs' ~/kvfs_mnt
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
you can mount it on multiple machines, so that when you edit the config files or `.env`
|
|
45
|
+
they will be updated on all of your machines
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Dependencies
|
|
49
|
+
|
|
50
|
+
you need `redis` and `pyfuse3`
|
|
51
|
+
which might need python development and fuse3 development
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
dnf install -y python3-devel fuse3-devel
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## How does it work
|
|
58
|
+
|
|
59
|
+
- `kvfs:meta:/path/to/file` stores the meta data of your file
|
|
60
|
+
- `kvfs:data:/path/to/file` stores the actual content
|
|
61
|
+
- `kvfs:dir:/path/to/dir/` stores the dir entry
|
|
62
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kvfs
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pykvfs"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Redis/Valkey backed FUSE filesystem"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Muayyad Alsadi" }
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
dependencies = [
|
|
18
|
+
"pyfuse3",
|
|
19
|
+
"redis[hiredis]",
|
|
20
|
+
"trio"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Operating System :: POSIX :: Linux",
|
|
26
|
+
"Topic :: System :: Filesystems"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
kvfs = "kvfs:main"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
py-modules = ["kvfs"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/muayyad-alsadi/pykvfs"
|
|
37
|
+
Repository = "https://github.com/muayyad-alsadi/pykvfs"
|
pykvfs-0.1.1/setup.cfg
ADDED