mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Add "per-process" file caching feature
Allows chosing page caching based on process name.
This commit is contained in:
parent
b51a5970b2
commit
9effeb6869
15 changed files with 363 additions and 55 deletions
54
src/procfs_get_name.cpp
Normal file
54
src/procfs_get_name.cpp
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue