Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ project(pmemfile C CXX)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
set(VERSION_MINOR 5)
set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})

Expand Down
6 changes: 4 additions & 2 deletions include/libpmemfile-posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ PMEMfile *pmemfile_open_parent(PMEMfilepool *pfp, PMEMfile *at,

const char *pmemfile_errormsg(void);

int pmemfile_pool_resume(PMEMfilepool *pfp, const char *pathname);
int pmemfile_pool_suspend(PMEMfilepool *pfp);
int pmemfile_pool_resume(PMEMfilepool *pfp, const char *pool_path,
unsigned at_root, const char * const *paths, int flags);
int pmemfile_pool_suspend(PMEMfilepool *pfp, unsigned at_root,
const char *const * paths, int flags);

#include "libpmemfile-posix-stubs.h"

Expand Down
63 changes: 63 additions & 0 deletions src/libpmemfile-posix/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,3 +979,66 @@ vinode_remove_interval(PMEMfilepool *pfp, struct pmemfile_vinode *vinode,

return deallocated_space;
}

/*
* vinode_read -- reads file
*/
size_t
vinode_read(PMEMfilepool *pfp, struct pmemfile_vinode *vinode, size_t offset,
struct pmemfile_block_desc **last_block, char *buf,
size_t count)
{
uint64_t size = inode_get_size(vinode->inode);

/*
* Start reading at offset, stop reading
* when end of file is reached, or count bytes were read.
* The following two branches compute how many bytes are
* going to be read.
*/
if (offset >= size)
return 0; /* EOF already */

if (size - offset < count)
count = size - offset;

struct pmemfile_block_desc *block =
find_closest_block_with_hint(vinode, offset, *last_block);

block = iterate_on_file_range(pfp, vinode, block, offset,
count, buf, read_from_blocks);

if (block)
*last_block = block;

return count;
}

/*
* vinode_write -- writes to file
*/
void
vinode_write(PMEMfilepool *pfp, struct pmemfile_vinode *vinode, size_t offset,
struct pmemfile_block_desc **last_block,
const char *buf, size_t count)
{
ASSERT(count > 0);

/*
* Two steps:
* - Zero Fill some new blocks, in case the file is extended by
* writing to the file after seeking past file size ( optionally )
* - Copy the data from the users buffer
*/

/* All blocks needed for writing are properly allocated at this point */

struct pmemfile_block_desc *block =
find_closest_block_with_hint(vinode, offset, *last_block);

block = iterate_on_file_range(pfp, vinode, block, offset,
count, (char *)buf, write_to_blocks);

if (block)
*last_block = block;
}
8 changes: 8 additions & 0 deletions src/libpmemfile-posix/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ struct pmemfile_block_desc *iterate_on_file_range(PMEMfilepool *pfp,
struct pmemfile_block_desc *starting_block, uint64_t offset,
uint64_t len, char *buf, enum cpy_direction dir);

void vinode_write(PMEMfilepool *pfp, struct pmemfile_vinode *vinode,
size_t offset, struct pmemfile_block_desc **last_block,
const char *buf, size_t count);

size_t vinode_read(PMEMfilepool *pfp, struct pmemfile_vinode *vinode,
size_t offset, struct pmemfile_block_desc **last_block,
char *buf, size_t count);

#endif
36 changes: 0 additions & 36 deletions src/libpmemfile-posix/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,6 @@ vinode_suspend(PMEMfilepool *pfp, struct pmemfile_vinode *vinode)
*tm = vinode->atime;
}

_inode_array_add(pfp, pfp->super->suspended_inodes, vinode->tinode,
&vinode->suspended.arr, &vinode->suspended.idx,
INODE_ARRAY_NOLOCK);

if (vinode->blocks) {
offset_map_delete(vinode->blocks);
vinode->blocks = NULL;
Expand All @@ -749,49 +745,17 @@ add_off(void *ptr, uintptr_t off)
return (void *)((uintptr_t)ptr + off);
}

/*
* inode_resume -- restores persistent part of inode after suspend
*/
void
inode_resume(PMEMfilepool *pfp, struct pmemfile_vinode *vinode,
PMEMobjpool *old_pop)
{
struct inode_suspend_info suspended = vinode->suspended;
struct pmemfile_inode *inode = vinode->inode;

ASSERT(vinode->suspended.arr != NULL);

if (pfp->pop != old_pop) {
uintptr_t diff = (uintptr_t)pfp->pop - (uintptr_t)old_pop;

suspended.arr = add_off(suspended.arr, diff);
inode = add_off(inode, diff);
}

ASSERT(inode->suspended_references > 0);

TX_ADD_DIRECT(&inode->suspended_references);
inode->suspended_references--;

_inode_array_unregister(pfp, suspended.arr, suspended.idx,
INODE_ARRAY_NOLOCK);
}

/*
* vinode_resume -- restores runtime part of inode after suspend
*/
void
vinode_resume(PMEMfilepool *pfp, struct pmemfile_vinode *vinode,
PMEMobjpool *old_pop)
{
vinode->suspended.arr = NULL;
vinode->suspended.idx = 0;

if (pfp->pop != old_pop) {
uintptr_t diff = (uintptr_t)pfp->pop - (uintptr_t)old_pop;

vinode->inode = add_off(vinode->inode, diff);

if (vinode->orphaned.arr)
vinode->orphaned.arr =
add_off(vinode->orphaned.arr, diff);
Expand Down
10 changes: 8 additions & 2 deletions src/libpmemfile-posix/inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ static inline bool vinode_is_longsymlink(struct pmemfile_vinode *vinode)

const char *get_symlink(PMEMfilepool *pfp, struct pmemfile_vinode *vinode);

static inline bool inode_has_suspended_refs(const struct pmemfile_inode *inode)
{
return (inode_get_flags(inode) & PMEMFILE_I_SUSPENDED_REF) != 0;
}

struct pmemfile_cred;
TOID(struct pmemfile_inode) inode_alloc(PMEMfilepool *pfp,
struct pmemfile_cred *cred, uint64_t flags);
Expand Down Expand Up @@ -404,9 +409,10 @@ blockp_as_oid(struct pmemfile_block_desc *block)
int vinode_rdlock_with_block_tree(PMEMfilepool *, struct pmemfile_vinode *);

void vinode_suspend(PMEMfilepool *pfp, struct pmemfile_vinode *vinode);
void inode_resume(PMEMfilepool *pfp, struct pmemfile_vinode *vinode,
PMEMobjpool *old_pop);
void vinode_resume(PMEMfilepool *pfp, struct pmemfile_vinode *vinode,
PMEMobjpool *old_pop);

/* 2 for "0x" 16 for pool_uuid 1 for ":" 2 for "0x" 16 for offset 1 for "\n" */
#define SUSPENDED_INODE_LINE_LENGTH (2 + 16 + 1 + 2 + 16 + 1)

#endif
13 changes: 9 additions & 4 deletions src/libpmemfile-posix/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ struct pmemfile_inode {
*/
COMPILE_ERROR_ON(sizeof(union pmemfile_inode_slots) != 8);

/*
* Most constants used with the flags field of pmemfile_inode are defined in the
* public header.
*
* Use the most significant 16 bits for flags only used internally. Hopefully
* this is not going to conflict with any flags in a Kernel API in the future.
*/
#define PMEMFILE_I_SUSPENDED_REF (UINT64_C(1) << 48)

COMPILE_ERROR_ON(sizeof(struct pmemfile_inode) != PMEMFILE_INODE_SIZE);

#define PMEMFILE_INODE_ARRAY_VERSION(a) ((uint32_t)0x00414E49 | \
Expand Down Expand Up @@ -294,9 +303,6 @@ struct pmemfile_super {
/* list of arrays of inodes that were deleted, but are still opened */
TOID(struct pmemfile_inode_array) orphaned_inodes;

/* list of arrays of inodes that are suspended */
TOID(struct pmemfile_inode_array) suspended_inodes;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump file system version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/*
* The array of root directories. Each one of them is a root of a
* separate directory tree. The path "/" resolves to root #0, all other
Expand All @@ -308,7 +314,6 @@ struct pmemfile_super {
char padding[PMEMFILE_SUPER_SIZE
- 8 /* version */
- 16 * (PMEMFILE_ROOT_COUNT) /* toid */
- 16 /* toid */
- 16 /* toid */];
};

Expand Down
Loading