mirror of https://github.com/trapexit/mergerfs.git
Browse Source
Add "per-process" file caching feature
Add "per-process" file caching feature
Allows chosing page caching based on process name.pull/1139/head
Antonio SJ Musumeci
2 years ago
15 changed files with 368 additions and 60 deletions
-
80README.md
-
8src/config.cpp
-
2src/config.hpp
-
4src/config_cachefiles.cpp
-
3src/config_cachefiles.hpp
-
43src/config_set.cpp
-
35src/config_set.hpp
-
41src/fs_openat.hpp
-
50src/fuse_create.cpp
-
37src/fuse_open.cpp
-
3src/mergerfs.cpp
-
54src/procfs_get_name.cpp
-
27src/procfs_get_name.hpp
-
32src/str.cpp
-
9src/str.hpp
@ -0,0 +1,43 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#include "config_set.hpp"
|
|||
|
|||
#include "str.hpp"
|
|||
|
|||
|
|||
ConfigSet::ConfigSet(const std::string &str_) |
|||
{ |
|||
from_string(str_); |
|||
} |
|||
|
|||
std::string |
|||
ConfigSet::to_string(void) const |
|||
{ |
|||
return str::join(*this,'|'); |
|||
} |
|||
|
|||
int |
|||
ConfigSet::from_string(const std::string &str_) |
|||
{ |
|||
this->clear(); |
|||
|
|||
str::split(str_,'|',this); |
|||
|
|||
return 0; |
|||
} |
@ -0,0 +1,35 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "tofrom_string.hpp"
|
|||
|
|||
#include <set>
|
|||
#include <string>
|
|||
|
|||
|
|||
class ConfigSet : public std::set<std::string>, public ToFromString |
|||
{ |
|||
public: |
|||
ConfigSet(const std::string &str); |
|||
|
|||
public: |
|||
std::string to_string(void) const final; |
|||
int from_string(const std::string &) final; |
|||
}; |
@ -0,0 +1,41 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include <sys/types.h>
|
|||
#include <sys/stat.h>
|
|||
#include <fcntl.h>
|
|||
#include <errno.h>
|
|||
|
|||
namespace fs |
|||
{ |
|||
static |
|||
inline |
|||
int |
|||
openat(const int dirfd_, |
|||
const char *pathname_, |
|||
const int flags_) |
|||
{ |
|||
int rv; |
|||
|
|||
rv = ::openat(dirfd_,pathname_,flags_); |
|||
|
|||
return ((rv == -1) ? -errno : rv); |
|||
} |
|||
} |
@ -0,0 +1,54 @@ |
|||
#ifndef _GNU_SOURCE
|
|||
#define _GNU_SOURCE
|
|||
#endif
|
|||
|
|||
#include "procfs_get_name.hpp"
|
|||
|
|||
#include "errno.hpp"
|
|||
#include "fs_close.hpp"
|
|||
#include "fs_open.hpp"
|
|||
#include "fs_openat.hpp"
|
|||
#include "fs_read.hpp"
|
|||
|
|||
#include <pthread.h>
|
|||
|
|||
static int g_PROCFS_DIR_FD = -1; |
|||
const char PROCFS_PATH[] = "/proc"; |
|||
|
|||
int |
|||
procfs::init() |
|||
{ |
|||
if(g_PROCFS_DIR_FD != -1) |
|||
return 0; |
|||
|
|||
g_PROCFS_DIR_FD = fs::open(PROCFS_PATH,O_PATH|O_DIRECTORY); |
|||
if(g_PROCFS_DIR_FD == -1) |
|||
return -errno; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
std::string |
|||
procfs::get_name(const int tid_) |
|||
{ |
|||
int fd; |
|||
int rv; |
|||
char commpath[256]; |
|||
|
|||
snprintf(commpath,sizeof(commpath),"%d/comm",tid_); |
|||
|
|||
fd = fs::openat(g_PROCFS_DIR_FD,commpath,O_RDONLY); |
|||
if(fd < 0) |
|||
return {}; |
|||
|
|||
rv = fs::read(fd,commpath,sizeof(commpath)); |
|||
if(rv == -1) |
|||
return {}; |
|||
|
|||
// Overwrite the newline with NUL
|
|||
commpath[rv-1] = '\0'; |
|||
|
|||
fs::close(fd); |
|||
|
|||
return commpath; |
|||
} |
@ -0,0 +1,27 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include <string>
|
|||
|
|||
namespace procfs |
|||
{ |
|||
int init(); |
|||
std::string get_name(const int tid); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue