Imported Upstream version 1.5.1
This commit is contained in:
47
cpp/include/ld_preload/environment.h
Normal file
47
cpp/include/ld_preload/environment.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2014 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRELOAD_ENVIRONMENT_H_
|
||||
#define PRELOAD_ENVIRONMENT_H_
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "libxtreemfs/system_user_mapping_unix.h"
|
||||
#include "libxtreemfs/volume_implementation.h"
|
||||
|
||||
#include "ld_preload/open_file_table.h"
|
||||
#include "ld_preload/path.h"
|
||||
#include "ld_preload/preload_options.h"
|
||||
|
||||
namespace xtreemfs {
|
||||
class Client;
|
||||
class VolumeHandle;
|
||||
}
|
||||
|
||||
class Environment {
|
||||
public:
|
||||
Environment();
|
||||
~Environment();
|
||||
//xtreemfs::Volume* GetVolume(const std::string& volume_name);
|
||||
xtreemfs::Volume* GetVolume();
|
||||
xtreemfs::SystemUserMappingUnix& GetSystemUserMapping();
|
||||
|
||||
|
||||
xtreemfs::PreloadOptions options_;
|
||||
xtreemfs::Client* client_;
|
||||
xtreemfs::Volume* volume_;
|
||||
std::string volume_name_;
|
||||
|
||||
/** Translates between local and remote usernames and groups. */
|
||||
xtreemfs::SystemUserMappingUnix system_user_mapping_;
|
||||
xtreemfs::pbrpc::UserCredentials user_creds_;
|
||||
OpenFileTable open_file_table_;
|
||||
};
|
||||
|
||||
#endif // PRELOAD_ENVIRONMENT_H_
|
||||
58
cpp/include/ld_preload/misc.h
Normal file
58
cpp/include/ld_preload/misc.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2014 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRELOAD_MISC_H_
|
||||
#define PRELOAD_MISC_H_
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "libxtreemfs/pbrpc_url.h"
|
||||
#include "xtreemfs/GlobalTypes.pb.h"
|
||||
|
||||
#include "ld_preload/environment.h"
|
||||
#include "ld_preload/passthrough.h"
|
||||
|
||||
xtreemfs::pbrpc::SYSTEM_V_FCNTL ConvertFlagsUnixToXtreemFS(int flags);
|
||||
int TranslateMode(const char* mode);
|
||||
int ConvertXtreemFSErrnoToUnix(xtreemfs::pbrpc::POSIXErrno xtreemfs_errno);
|
||||
|
||||
template<class T>
|
||||
void ConvertXtreemFSStatToUnix(const xtreemfs::pbrpc::Stat& xtreemfs_stat, T* unix_stat, xtreemfs::SystemUserMappingUnix& system_user_mapping) {
|
||||
unix_stat->st_dev = xtreemfs_stat.dev();
|
||||
unix_stat->st_blksize = 8 * 128 * 1024;
|
||||
unix_stat->st_ino = xtreemfs_stat.ino(); // = fileId
|
||||
unix_stat->st_mode = xtreemfs_stat.mode();
|
||||
unix_stat->st_nlink = xtreemfs_stat.nlink();
|
||||
|
||||
// Map user- and groupnames.
|
||||
unix_stat->st_uid = system_user_mapping.UsernameToUID(xtreemfs_stat.user_id());
|
||||
unix_stat->st_gid = system_user_mapping.GroupnameToGID(xtreemfs_stat.group_id());
|
||||
|
||||
unix_stat->st_size = xtreemfs_stat.size();
|
||||
#ifdef __linux
|
||||
unix_stat->st_atim.tv_sec = xtreemfs_stat.atime_ns() / 1000000000;
|
||||
unix_stat->st_atim.tv_nsec = xtreemfs_stat.atime_ns() % 1000000000;
|
||||
unix_stat->st_mtim.tv_sec = xtreemfs_stat.mtime_ns() / 1000000000;
|
||||
unix_stat->st_mtim.tv_nsec = xtreemfs_stat.mtime_ns() % 1000000000;
|
||||
unix_stat->st_ctim.tv_sec = xtreemfs_stat.ctime_ns() / 1000000000;
|
||||
unix_stat->st_ctim.tv_nsec = xtreemfs_stat.ctime_ns() % 1000000000;
|
||||
#elif __APPLE__
|
||||
unix_stat->st_atimespec.tv_sec = xtreemfs_stat.atime_ns() / 1000000000;
|
||||
unix_stat->st_atimespec.tv_nsec = xtreemfs_stat.atime_ns() % 1000000000;
|
||||
unix_stat->st_mtimespec.tv_sec = xtreemfs_stat.mtime_ns() / 1000000000;
|
||||
unix_stat->st_mtimespec.tv_nsec = xtreemfs_stat.mtime_ns() % 1000000000;
|
||||
unix_stat->st_ctimespec.tv_sec = xtreemfs_stat.ctime_ns() / 1000000000;
|
||||
unix_stat->st_ctimespec.tv_nsec = xtreemfs_stat.ctime_ns() % 1000000000;
|
||||
#endif
|
||||
|
||||
unix_stat->st_rdev = 0;
|
||||
unix_stat->st_blocks = xtreemfs_stat.size() / 512;
|
||||
}
|
||||
|
||||
#endif // PRELOAD_MISC_H_
|
||||
61
cpp/include/ld_preload/open_file_table.h
Normal file
61
cpp/include/ld_preload/open_file_table.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2014 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRELOAD_OPEN_FILE_TABLE_H_
|
||||
#define PRELOAD_OPEN_FILE_TABLE_H_
|
||||
|
||||
#include <map>
|
||||
#include <pthread.h>
|
||||
#include <cstdio>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include "libxtreemfs/file_handle.h"
|
||||
|
||||
namespace xtreemfs {
|
||||
class Client;
|
||||
class VolumeHandle;
|
||||
}
|
||||
|
||||
class OpenFile {
|
||||
public:
|
||||
OpenFile(xtreemfs::FileHandle* fh);
|
||||
|
||||
void Initialise();
|
||||
void Deinitialise();
|
||||
int GetFileDescriptor();
|
||||
|
||||
xtreemfs::FileHandle* fh_;
|
||||
uint64_t offset_;
|
||||
|
||||
private:
|
||||
FILE * tmp_file_;
|
||||
int tmp_file_fd_;
|
||||
};
|
||||
|
||||
class OpenFileTable {
|
||||
public:
|
||||
OpenFileTable();
|
||||
~OpenFileTable();
|
||||
|
||||
int Register(xtreemfs::FileHandle* handle);
|
||||
void Unregister(int fd);
|
||||
OpenFile Get(int fd);
|
||||
int Set(int fd, xtreemfs::FileHandle* handle);
|
||||
void SetOffset(int fd, uint64_t offset);
|
||||
bool Has(int fd);
|
||||
|
||||
private:
|
||||
boost::mutex mutex_;
|
||||
typedef std::map<int, OpenFile> FileTable;
|
||||
FileTable open_files_;// GUARDED_BY(mutex_);
|
||||
FILE * tmp_file_;
|
||||
int tmp_file_fd_;
|
||||
int next_fd_;
|
||||
};
|
||||
|
||||
#endif // PRELOAD_OPEN_FILE_TABLE_H_
|
||||
79
cpp/include/ld_preload/passthrough.h
Normal file
79
cpp/include/ld_preload/passthrough.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2014 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRELOAD_PASSTHROUGH_H_
|
||||
#define PRELOAD_PASSTHROUGH_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef int (*funcptr_open)(const char*, int, int);
|
||||
typedef int (*funcptr_close)(int);
|
||||
|
||||
typedef ssize_t (*funcptr_read)(int, void*, size_t);
|
||||
typedef ssize_t (*funcptr_write)(int, const void*, size_t);
|
||||
typedef ssize_t (*funcptr_pread)(int, void*, size_t, off_t);
|
||||
typedef ssize_t (*funcptr_pwrite)(int, const void*, size_t, off_t);
|
||||
|
||||
typedef int (*funcptr_dup)(int);
|
||||
typedef int (*funcptr_dup2)(int, int);
|
||||
typedef off_t (*funcptr_lseek)(int, off_t, int);
|
||||
|
||||
typedef int (*funcptr_stat)(const char*, struct stat*);
|
||||
typedef int (*funcptr_fstat)(int, struct stat*);
|
||||
typedef int (*funcptr___xstat)(int, const char*, struct stat*);
|
||||
typedef int (*funcptr___xstat64)(int, const char*, struct stat64*);
|
||||
typedef int (*funcptr___fxstat)(int, int, struct stat*);
|
||||
typedef int (*funcptr___fxstat64)(int, int, struct stat64*);
|
||||
typedef int (*funcptr___lxstat)(int, const char*, struct stat*);
|
||||
typedef int (*funcptr___lxstat64)(int, const char*, struct stat64*);
|
||||
|
||||
typedef FILE* (*funcptr_fopen)(const char*, const char*);
|
||||
typedef int (*funcptr_truncate)(const char*, off_t);
|
||||
typedef int (*funcptr_ftruncate)(int, off_t);
|
||||
|
||||
typedef int (*funcptr_setxattr)(const char*, const char*, const void*, size_t, int);
|
||||
typedef int (*funcptr_fsetxattr)(int, const char*, const void*, size_t, int);
|
||||
|
||||
|
||||
extern void* libc_open;
|
||||
extern void* libc_close;
|
||||
extern void* libc___close;
|
||||
extern void* libc_pread;
|
||||
extern void* libc_read;
|
||||
extern void* libc_write;
|
||||
extern void* libc_dup;
|
||||
extern void* libc_dup2;
|
||||
extern void* libc_lseek;
|
||||
|
||||
extern void* libc_stat;
|
||||
extern void* libc_fstat;
|
||||
extern void* libc___xstat;
|
||||
extern void* libc___xstat64;
|
||||
extern void* libc___fxstat;
|
||||
extern void* libc___fxstat64;
|
||||
extern void* libc___lxstat;
|
||||
extern void* libc___lxstat64;
|
||||
|
||||
extern void* libc_fopen;
|
||||
extern void* libc_truncate;
|
||||
extern void* libc_ftruncate;
|
||||
|
||||
extern void* libattr_setxattr;
|
||||
extern void* libattr_fsetxattr;
|
||||
|
||||
void initialize_passthrough_if_necessary();
|
||||
|
||||
#ifdef XTREEMFS_PRELOAD_QUIET
|
||||
#define xprintf(...)
|
||||
#else
|
||||
#define xprintf(...) fprintf(xtreemfs_stdout() ? xtreemfs_stdout() : stdout, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
FILE* xtreemfs_stdout();
|
||||
|
||||
#endif // PRELOAD_PASSTHROUGH_H_
|
||||
29
cpp/include/ld_preload/path.h
Normal file
29
cpp/include/ld_preload/path.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2014 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRELOAD_PATH_H_
|
||||
#define PRELOAD_PATH_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
class Path {
|
||||
public:
|
||||
Path(const char* pathname);
|
||||
|
||||
bool IsXtreemFS();
|
||||
void Parse();
|
||||
const char* GetXtreemFSPath();
|
||||
static void SetXtreemFSPrefix(const std::string& prefix);
|
||||
|
||||
private:
|
||||
static std::string& GetXtreemFSPrefix();
|
||||
|
||||
const char* pathname_;
|
||||
const char* xtreemfs_path_;
|
||||
};
|
||||
|
||||
#endif // PRELOAD_PATH_H_
|
||||
39
cpp/include/ld_preload/preload.h
Normal file
39
cpp/include/ld_preload/preload.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2014 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRELOAD_PRELOAD_H_
|
||||
#define PRELOAD_PRELOAD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "ld_preload/environment.h"
|
||||
|
||||
bool overlay_initialized(bool toggle = false);
|
||||
Environment* get_env();
|
||||
|
||||
bool is_xtreemfs_fd(int fd);
|
||||
bool is_xtreemfs_path(const char *path);
|
||||
|
||||
int xtreemfs_open(const char* pathname, int flags, int mode);
|
||||
int xtreemfs_close(int fd);
|
||||
uint64_t xtreemfs_pread(int fd, void* buf, uint64_t nbyte, uint64_t offset);
|
||||
uint64_t xtreemfs_read(int fd, void* buf, uint64_t nbyte);
|
||||
uint64_t xtreemfs_write(int fd, const void* buf, uint64_t nbyte);
|
||||
int xtreemfs_dup2(int oldfd, int newfd);
|
||||
int xtreemfs_dup(int fd);
|
||||
off_t xtreemfs_lseek(int fd, off_t offset, int mode);
|
||||
int xtreemfs_stat(const char *path, struct stat *buf);
|
||||
int xtreemfs_stat64(const char *pathname, struct stat64 *buf);
|
||||
int xtreemfs_fstat(int fd, struct stat *buf);
|
||||
int xtreemfs_fstat64(int fd, struct stat64 *buf);
|
||||
|
||||
int xtreemfs_setxattr(const char *pathname, const char *name, const void *value, size_t size, int flags);
|
||||
int xtreemfs_fsetxattr(int fd, const char *name, const void *value, size_t size, int flags);
|
||||
|
||||
#endif // PRELOAD_PRELOAD_H_
|
||||
|
||||
45
cpp/include/ld_preload/preload_options.h
Normal file
45
cpp/include/ld_preload/preload_options.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2014 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CPP_INCLUDE_LD_PRELOAD_PRELOAD_OPTIONS_H_
|
||||
#define CPP_INCLUDE_LD_PRELOAD_PRELOAD_OPTIONS_H_
|
||||
|
||||
#include "libxtreemfs/options.h"
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace xtreemfs {
|
||||
|
||||
class PreloadOptions : public Options {
|
||||
public:
|
||||
/** Sets the default values. */
|
||||
PreloadOptions();
|
||||
|
||||
/** Set options parsed from command line which must contain at least the URL
|
||||
* to an XtreemFS volume.
|
||||
*
|
||||
* Calls Options::ParseCommandLine() to parse general options.
|
||||
*
|
||||
* @throws InvalidCommandLineParametersException
|
||||
* @throws InvalidURLException */
|
||||
void ParseCommandLine(int argc, char** argv);
|
||||
|
||||
/** Outputs usage of the command line parameters. */
|
||||
virtual std::string ShowCommandLineHelp();
|
||||
|
||||
// TODO: add preload-specific options here
|
||||
|
||||
private:
|
||||
/** Contains all available preload options and its descriptions. */
|
||||
boost::program_options::options_description preload_descriptions_;
|
||||
};
|
||||
|
||||
} // namespace xtreemfs
|
||||
|
||||
#endif // CPP_INCLUDE_LD_PRELOAD_PRELOAD_OPTIONS_H_
|
||||
Reference in New Issue
Block a user