Skip to content

Commit b11829b

Browse files
committed
Developing: add monopoly layer
1 parent 2d4c42e commit b11829b

File tree

6 files changed

+108
-18
lines changed

6 files changed

+108
-18
lines changed

simple_fs/file.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,34 @@ void simple_fs_lseek(struct spdkfs_file *file, loff_t offset, int f_flag, void *
2424
{
2525

2626
}
27-
void simple_fs_read(struct spdkfs_file *file, size_t size, loff_t *buffer, void *cb_args)
27+
void simple_fs_read(struct spdkfs_file *file, size_t size, void *buffer, void *cb_args)
2828
{
2929

3030
}
31-
void simple_fs_write(struct spdkfs_file *file, size_t size, loff_t *buffer, void *cb_args)
31+
void simple_fs_write(struct spdkfs_file *file, size_t size, void *buffer, void *cb_args)
3232
{
33-
33+
struct general_op_cb_args *args = cb_args;
3434
}
3535
void simple_fs_open(struct spdk_blob *blob, struct spdkfs_file *file, void *cb_args)
3636
{
3737
struct general_op_cb_args *args = cb_args;
3838
file->_blob = blob;
39-
file->file_persist-> f_size = spdk_blob_get_num_pages(blob) * spdk_bs_get_page_size(args->fs);
40-
file->f_pos = 0;
39+
struct file_persistent_ctx *file_persistent;
40+
spdk_blob_get_xattr_value(blob, "file_persistent", &file_persistent, sizeof(struct spdkfs_file_persist_ctx));
41+
file->file_persist = file_persistent;
42+
43+
4144
}
4245
void simple_fs_create(struct spdk_blob *blob, struct spdkfs_file *file, void *cb_args)
4346
{
47+
struct simple_fs_cb_args *args = cb_args;
4448
file->_blob = blob;
49+
file->file_persist->f_size = 0;
50+
file->file_persist->i_parent_blob_id = spdk_blob_get_id(file->_blob);
51+
file->file_persist->i_writecount = 0;
52+
file->file_persist->i_ctime = time(NULL);
53+
spdk_blob_set_xattr(blob, "file_persistent", file->file_persist, sizeof(struct spdkfs_file_persist_ctx));
54+
4555
}
4656
void simple_fs_release(struct spdk_blob *blob, struct spdkfs_file *file, void *cb_args)
4757
{

simple_fs/file.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void simple_fs_lseek(struct spdkfs_file *, loff_t, int, void *);
5656
* \param file_param context for file operations
5757
\
5858
*/
59-
void simple_fs_read(struct spdkfs_file *, size_t, loff_t *, void *);
59+
void simple_fs_read(struct spdkfs_file *, size_t, void*, void *);
6060
/**
6161
* Write the data to the given file
6262
*
@@ -67,7 +67,7 @@ void simple_fs_read(struct spdkfs_file *, size_t, loff_t *, void *);
6767
\
6868
*/
6969

70-
void simple_fs_write(struct spdkfs_file *, size_t, loff_t *, void *);
70+
void simple_fs_write(struct spdkfs_file *, size_t, void* , void *);
7171
/**
7272
* Filling the file persistent structure with the give blob
7373
*
@@ -92,7 +92,7 @@ void simple_fs_create(struct spdk_blob *, struct spdkfs_file *, void *);
9292
*
9393
* \param blob blob to read file metadata
9494
* \param file file structure to fill
95-
* \param file_param context for file operations
95+
* \param file_param context for file operations : operation parameters, parent dir blobid
9696
*
9797
*/
9898
void simple_fs_release(struct spdk_blob *, struct spdkfs_file *, void *);

simple_fs/monopoly_ops.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "monopoly_ops.h"
2+
#include "blob_op.h"
3+
4+
static struct fdtable g_fdtable;
5+
static struct spdkfs_dir* g_workdir;
6+
7+
static int find_dir(const char* filename,struct spdkfs_dir *_dir)
8+
{
9+
for(int i = 0; i < _dir->dirent_count; ++i)
10+
{
11+
if(strcmp(filename, _dir->dirents[i].d_ctx._name) == 0)
12+
{
13+
return i;
14+
}
15+
}
16+
return -1;
17+
}
18+
19+
int monopoly_open(const char *__file, int __oflag)
20+
{
21+
int dirent_num = find_dir(__file, g_workdir);
22+
if(dirent_num == -1)
23+
{
24+
SPDK_ERRLOG("Cannot find file!\n");
25+
return -1;
26+
}
27+
struct spdk_blob* blob;
28+
blob_open(&blob, g_workdir->dirents[dirent_num].d_ctx.id);
29+
struct spdkfs_file* file = malloc(sizeof(struct spdkfs_file));
30+
simple_fs_open(blob, file, NULL);
31+
}
32+
int monopoly_close(int __fd)
33+
{
34+
35+
}
36+
37+
ssize_t monopoly_read(int __fd, void *__buf, size_t __nbytes)
38+
{
39+
40+
}
41+
42+
ssize_t monopoly_write(int __fd, const void *__buf, size_t __nbytes)
43+
{
44+
45+
}
46+
47+
48+
__off_t monopolyk_lseek(int __fd, __off_t __offset, int __whence)
49+
{
50+
51+
}
52+

simple_fs/monopoly_ops.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef __spdk_fs_monopoly_op_h__
2+
#define __spdk_fs_monopoly_op_h__
3+
4+
#include "spdkfs/fs.h"
5+
#include "file.h"
6+
7+
int monopoly_open(const char *__file, int __oflag);
8+
int monopoly_close(int __fd);
9+
10+
ssize_t monopoly_read(int __fd, void *__buf, size_t __nbytes);
11+
12+
ssize_t monopoly_write(int __fd, const void *__buf, size_t __nbytes);
13+
14+
15+
__off_t monopolyk_lseek(int __fd, __off_t __offset, int __whence);
16+
17+
18+
#endif

simple_fs/super.c

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ static void load_root()
6969
super_blob_persist->i_mtime = time(NULL);
7070
super_blob_persist->i_parent_blob_id = 0;
7171
super_blob_persist->i_writecount = 1;
72-
super_blob_persist->i_is_dir = true;
7372

7473
size = spdk_blob_get_num_clusters(g_filesystem->super_blob->blob);
7574
SPDK_WARNLOG("Size after risize %lu\n", size);

spdk_fs/fs.h

+20-9
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ typedef void(*spdk_fs_callback)(void *cb_arg);
3737
struct spdkfs_file_persist_ctx {
3838
unsigned int i_uid;
3939
unsigned int i_gid;
40-
dev_t i_rdev;
4140
long i_atime;
4241
long i_mtime;
4342
long i_ctime;
4443
size_t f_size;
4544
unsigned int i_writecount;
4645
uint64_t i_parent_blob_id;
47-
bool i_is_dir;
4846
bool dirty;
4947
} __attribute__((aligned(4)));
5048

@@ -63,11 +61,24 @@ struct fdtable {
6361
struct spdkfs_file *open_files[SPDK_MAX_FILE_CNT];
6462
};
6563

64+
65+
struct spdkfs_dir_persist_ctx {
66+
unsigned int i_uid;
67+
unsigned int i_gid;
68+
long i_atime;
69+
long i_mtime;
70+
long i_ctime;
71+
size_t d_size;
72+
unsigned int i_writecount;
73+
uint64_t i_parent_blob_id;
74+
bool dirty;
75+
} __attribute__((aligned(4)));
76+
6677
struct spdkfs_dir {
6778
struct blob *blob;
6879
const struct spdk_file_operations *d_op;
6980
unsigned int d_flags;
70-
struct spdkfs_file_persist_ctx *dir_persist;
81+
struct spdkfs_dir_persist_ctx *dir_persist;
7182

7283
bool initialized;
7384
int dirent_count;
@@ -95,14 +106,14 @@ struct spdk_fs_operations {
95106

96107
// All file operations should be perform at upper layer
97108
struct spdk_file_operations {
98-
void (*spdk_lseek)(struct spdkfs_file *, loff_t, int, void *);
99-
void (*spdk_read)(struct spdkfs_file *, size_t, loff_t *, void *);
100-
void (*spdk_write)(struct spdkfs_file *, size_t, loff_t *, void *);
109+
void (*spdk_lseek)(struct spdkfs_file *file, loff_t offset, int mode, void *);
110+
void (*spdk_read)(struct spdkfs_file *file, size_t size, void* buffer, void * fs_ctx);
111+
void (*spdk_write)(struct spdkfs_file *file, size_t size, void* buffer, void *fs_ctx);
101112
// int (*spdk_mmap) (struct spdkfs_file *, struct vm_area_struct *);
102113
unsigned long mmap_supported_flags;
103-
void (*spdk_open)(struct spdk_blob *, struct spdkfs_file *, void *);
104-
void (*spdk_create)(struct spdk_blob *, struct spdkfs_file *, void *);
105-
void (*spdk_release)(struct spdk_blob *, struct spdkfs_file *, void *);
114+
void (*spdk_open)(struct spdk_blob *blob, struct spdkfs_file *file, void *);
115+
void (*spdk_create)(struct spdk_blob *blob, struct spdkfs_file *file, void *);
116+
void (*spdk_release)(struct spdk_blob *blob, struct spdkfs_file *file, void *);
106117
};
107118

108119
struct spdk_fs_init_ctx {

0 commit comments

Comments
 (0)