Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions turbonfs/inc/fs-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ static void aznfsc_ll_open(fuse_req_t req,
AZLogDebug("aznfsc_ll_open(req={}, ino={}, fi={})",
fmt::ptr(req), ino, fmt::ptr(fi));

struct nfs_client *client = get_nfs_client_from_fuse_req(req);
struct nfs_inode *inode = client->get_nfs_inode_from_ino(ino);

// Make sure it's not called for directories.
assert(!inode->is_dir());

/*
* Should we require kernel cache for this inode?
* We enable kernel cache explicit for tar and zip files.
*/
bool require_kernel_cache = inode->get_require_kernel_cache();
require_kernel_cache = require_kernel_cache ? true : aznfsc_cfg.cache.data.kernel.enable;

/*
* We plan to manage our own file cache for better control over writes.
*
Expand All @@ -322,8 +335,8 @@ static void aznfsc_ll_open(fuse_req_t req,
* doesn't send another write before the prev one completes. We depend
* on that.
*/
fi->direct_io = !aznfsc_cfg.cache.data.kernel.enable;
fi->keep_cache = aznfsc_cfg.cache.data.kernel.enable;
fi->direct_io = !require_kernel_cache;
fi->keep_cache = require_kernel_cache;
fi->nonseekable = 0;
fi->parallel_direct_writes = 0;
fi->noflush = 0;
Expand All @@ -334,12 +347,6 @@ static void aznfsc_ll_open(fuse_req_t req,
*/
fi->fh = 12345678;

struct nfs_client *client = get_nfs_client_from_fuse_req(req);
struct nfs_inode *inode = client->get_nfs_inode_from_ino(ino);

// Make sure it's not called for directories.
assert(!inode->is_dir());

/*
* For cto consistency open should force revalidate the inode by making a
* getattr call and if that indicates that file data has changed (mtime
Expand Down Expand Up @@ -741,8 +748,11 @@ static void aznfsc_ll_create(fuse_req_t req,
/*
* See aznfsc_ll_open().
*/
fi->direct_io = !aznfsc_cfg.cache.data.kernel.enable;
fi->keep_cache = aznfsc_cfg.cache.data.kernel.enable;
bool require_kernel_cache = has_tar_or_zip_extension(name);
require_kernel_cache = require_kernel_cache ? true : aznfsc_cfg.cache.data.kernel.enable;

fi->direct_io = !require_kernel_cache;
fi->keep_cache = require_kernel_cache;
fi->nonseekable = 0;
fi->parallel_direct_writes = 0;
fi->noflush = 0;
Expand Down
3 changes: 2 additions & 1 deletion turbonfs/inc/nfs_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ struct nfs_client
struct nfs_inode *__get_nfs_inode(LOC_PARAMS
const nfs_fh3 *fh,
const struct fattr3 *fattr,
bool is_root_inode = false);
bool is_root_inode = false,
bool require_kernel_cache = false);

#define get_nfs_inode(fh, fattr, ...) \
__get_nfs_inode(LOC_VAL fh, fattr, ## __VA_ARGS__)
Expand Down
17 changes: 16 additions & 1 deletion turbonfs/inc/nfs_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ struct nfs_inode
* IMPORTANT: Need to ensure time is sync'ed and it doesn't go back.
*/
const fuse_ino_t ino;

/*
* Does this inode require kernel cache?
*/
const bool require_kernel_cache;

const uint64_t generation;

/*
Expand Down Expand Up @@ -462,7 +468,8 @@ struct nfs_inode
const struct fattr3 *fattr,
struct nfs_client *_client,
uint32_t _file_type,
fuse_ino_t _ino = 0);
fuse_ino_t _ino = 0,
bool require_kernel_cache = false);

~nfs_inode();

Expand Down Expand Up @@ -1791,6 +1798,14 @@ struct nfs_inode
return stable_write;
}

/**
* Does this inode require kernel cache?
*/
bool get_require_kernel_cache() const
{
return require_kernel_cache;
}

/**
* Directory cache lookup method.
*
Expand Down
5 changes: 5 additions & 0 deletions turbonfs/inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ namespace aznfsc {
*/
uint64_t get_total_ram();

/*
* Check file extension has tar or zip.
*/
bool has_tar_or_zip_extension(const char *filename);

/**
* Set readahead_kb for kernel readahead.
* This sets the kernel readahead value of aznfsc_cfg.readahead_kb iff kernel
Expand Down
21 changes: 16 additions & 5 deletions turbonfs/src/nfs_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ bool nfs_client::init()
*/
root_fh = get_nfs_inode(nfs_get_rootfh(transport.get_nfs_context()),
&fattr,
true /* is_root_inode */);
true /* is_root_inode */,
false /* require_kernel_cache */);
assert(root_fh->lookupcnt == 1);
assert(root_fh->dircachecnt == 0);

Expand Down Expand Up @@ -740,7 +741,8 @@ struct nfs_inode *nfs_client::__inode_from_inode_map(const nfs_fh3 *fh,
struct nfs_inode *nfs_client::__get_nfs_inode(LOC_PARAMS
const nfs_fh3 *fh,
const struct fattr3 *fattr,
bool is_root_inode)
bool is_root_inode,
bool require_kernel_cache)
{
assert(fh);
assert(fattr);
Expand Down Expand Up @@ -864,7 +866,8 @@ struct nfs_inode *nfs_client::__get_nfs_inode(LOC_PARAMS

struct nfs_inode *new_inode =
new nfs_inode(fh, fattr, this, file_type,
is_root_inode ? FUSE_ROOT_ID : 0);
is_root_inode ? FUSE_ROOT_ID : 0,
require_kernel_cache);

{
std::unique_lock<std::shared_mutex> lock(inode_map_lock_0);
Expand Down Expand Up @@ -1205,10 +1208,13 @@ static void lookup_sync_callback(
if (status == 0) {
assert(res->LOOKUP3res_u.resok.obj_attributes.attributes_follow);

bool require_kernel_cache = has_tar_or_zip_extension(
task->rpc_api->lookup_task.get_file_name());
const nfs_fh3 *fh = (const nfs_fh3 *) &res->LOOKUP3res_u.resok.object;
const struct fattr3 *fattr =
(const struct fattr3 *) &res->LOOKUP3res_u.resok.obj_attributes.post_op_attr_u.attributes;
const struct nfs_inode *inode = task->get_client()->get_nfs_inode(fh, fattr);
const struct nfs_inode *inode = task->get_client()->get_nfs_inode(fh, fattr, false /* is_root_inode */,
require_kernel_cache);
(*child_ino_p) = inode->get_fuse_ino();
if (ctx->fattr) {
*(ctx->fattr) = *fattr;
Expand Down Expand Up @@ -1997,6 +2003,11 @@ void nfs_client::reply_entry(
enum fuse_opcode optype = task->get_op_type();
struct nfs_inode *inode = nullptr;
fuse_entry_param entry;
bool require_kernel_cache = false;
if (file) {
require_kernel_cache = file->keep_cache;
}

/*
* Kernel must cache lookup result.
*/
Expand All @@ -2013,7 +2024,7 @@ void nfs_client::reply_entry(
* This will grab a lookupcnt ref on the inode, which will be freed
* from fuse forget callback.
*/
inode = get_nfs_inode(fh, fattr);
inode = get_nfs_inode(fh, fattr, false, require_kernel_cache);

entry.ino = inode->get_fuse_ino();
entry.generation = inode->get_generation();
Expand Down
4 changes: 3 additions & 1 deletion turbonfs/src/nfs_inode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ nfs_inode::nfs_inode(const struct nfs_fh3 *filehandle,
const struct fattr3 *fattr,
struct nfs_client *_client,
uint32_t _file_type,
fuse_ino_t _ino) :
fuse_ino_t _ino,
bool require_kernel_cache) :
file_type(_file_type),
fh(*filehandle),
crc(calculate_crc32(fh.get_fh())),
ino(_ino == 0 ? (fuse_ino_t) this : _ino),
require_kernel_cache(require_kernel_cache),
generation(get_current_usecs()),
client(_client)
{
Expand Down
23 changes: 23 additions & 0 deletions turbonfs/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ uint64_t get_total_ram()
return num_pages * page_size;
}

/*
* Check file extension has tar or zip.
*/
bool has_tar_or_zip_extension(const char *filename)
{
assert(filename != nullptr);

const char *ext = ::strrchr(filename, '.');
if (ext == nullptr) {
return false;
}

if ((::strcasecmp(ext, ".tar") == 0) ||
(::strcasecmp(ext, ".zip") == 0) ||
(::strcasecmp(ext, ".tar.gz") == 0) ||
(::strcasecmp(ext, ".tgz") == 0)) {
return true;
}

return false;
}


/**
* Set readahead_kb for kernel readahead.
* This sets the kernel readahead value of aznfsc_cfg.readahead_kb iff kernel
Expand Down