Skip to content

Commit

Permalink
Merge pull request #71 from ToolmanP/main
Browse files Browse the repository at this point in the history
Lab4/5: enhance hints and typo fix
  • Loading branch information
ToolmanP authored Dec 19, 2024
2 parents 1b9a52c + 57e5a0c commit e01170e
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Lab4/kernel/sched/policy_rr.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ int rr_sched(void)
switch_to_thread(old);
return 0; /* no schedule needed */
}
/* LAB 4 TODO BEGIN (exercise 6) */
/* LAB 4 TODO BEGIN (exercise 4) */
/* Refill budget for current running thread (old) and enqueue the current thread.*/

/* LAB 4 TODO END (exercise 6) */
/* LAB 4 TODO END (exercise 4) */

} else if (!thread_is_ts_blocking(old)
&& !thread_is_ts_waiting(old)) {
Expand Down
7 changes: 5 additions & 2 deletions Lab5/user/system-services/system-servers/fs_base/fs_vnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ void fs_vnode_init(void)
struct fs_vnode *alloc_fs_vnode(ino_t id, enum fs_vnode_type type, off_t size,
void *private)
{
/* Lab 5 TODO Begin (TODO 2) */
/* Lab 5 TODO Begin (Part 2) */

return NULL;

/* Lab 5 TODO End (TODO 2) */
/* Lab 5 TODO End (Part 2) */
}

void push_fs_vnode(struct fs_vnode *n)
Expand All @@ -117,6 +117,7 @@ void pop_free_fs_vnode(struct fs_vnode *n)
struct fs_vnode *get_fs_vnode_by_id(ino_t vnode_id)
{
/* Lab 5 TODO Begin (Part 2) */
/* Use the rb_xxx api */
return NULL;
/* Lab 5 TODO End (Part 2) */
}
Expand All @@ -125,6 +126,7 @@ struct fs_vnode *get_fs_vnode_by_id(ino_t vnode_id)
int inc_ref_fs_vnode(void *private)
{
/* Lab 5 TODO Begin (Part 2) */
/* Private is a fs_vnode */
UNUSED(private);
return 0;
/* Lab 5 TODO End (Part 2) */
Expand All @@ -133,6 +135,7 @@ int inc_ref_fs_vnode(void *private)
int dec_ref_fs_vnode(void *private)
{
/* Lab 5 TODO Begin (Part 2) */
/* Private is a fs_vnode Decrement its refcnt */
UNUSED(private);
return 0;
/* Lab 5 TODO End (Part 2) */
Expand Down
23 changes: 12 additions & 11 deletions Lab5/user/system-services/system-servers/fs_base/fs_wrapper.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* Licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS),
* Shanghai Jiao Tong University (SJTU) Licensed under the Mulan PSL v2. You can
* use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
* Mulan PSL v2 for more details.
*/

#include "chcore-internal/procmgr_defs.h"
Expand Down Expand Up @@ -108,20 +108,21 @@ void init_fs_wrapper(void)

/* +++++++++++++++++++++++++++ FID Mapping ++++++++++++++++++++++++++++++++ */

/* Same as the previous fs_cap_table. Organize it in linked list */
/* Get (client_badge, fd) -> fid(server_entry) mapping */
int fs_wrapper_get_server_entry(badge_t client_badge, int fd)
{
/* Lab 5 TODO Begin (TODO 3)*/
/* Lab 5 TODO Begin (Part 3)*/
return -1;
/* Lab 5 TODO End (TODO 3)*/
/* Lab 5 TODO End (Part 3)*/
}

/* Set (client_badge, fd) -> fid(server_entry) mapping */
int fs_wrapper_set_server_entry(badge_t client_badge, int fd, int fid)
{
/* Lab 5 TODO Begin (TODO 3)*/
/* Lab 5 TODO Begin (Part 3)*/
return 0;
/* Lab 5 TODO End (TODO 3)*/
/* Lab 5 TODO End (Part 3)*/
}

void fs_wrapper_clear_server_entry(badge_t client_badge, int fid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ struct fs_server_ops {
ssize_t (*read)(void *operator, off_t offset, size_t size, char *buf);
ssize_t (*write)(void *operator, off_t offset, size_t size,
const char *buf);

/* NOTE: close operates on a private vnode return by open*/
int (*close)(void *operator, bool is_dir, bool do_close);
int (*chmod)(char *pathname, mode_t mode);

Expand Down
73 changes: 54 additions & 19 deletions Lab5/user/system-services/system-servers/fs_base/fs_wrapper_ops.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* Licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS),
* Shanghai Jiao Tong University (SJTU) Licensed under the Mulan PSL v2. You can
* use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
* Mulan PSL v2 for more details.
*/

#include "chcore/proc.h"
Expand Down Expand Up @@ -118,17 +118,41 @@ ssize_t default_ssize_t_server_operation(ipc_msg_t *ipc_msg,
int fs_wrapper_open(badge_t client_badge, ipc_msg_t *ipc_msg,
struct fs_request *fr)
{
/* Lab 5 TODO Begin (TODO 4)*/
/* Lab 5 TODO Begin (Part 4)*/
/* Check the fr permission and open flag if necessary */

/* Use server_ops to open the file */

/* Check if the vnode_id is in rb tree.*/

/* If not, create a new vnode and insert it into the tree. */

/* If yes, then close the newly opened vnode and increment the refcnt of
* present vnode */

/* Alloc a server_entry and assign the vnode and client generated
* fd(fr->xxx) to it (Part3 Server fid)*/

/* Return the client fd */

return 0;
/* Lab 5 TODO End (TODO 4)*/
/* Lab 5 TODO End (Part 4)*/
}

int fs_wrapper_close(badge_t client_badge, ipc_msg_t *ipc_msg,
struct fs_request *fr)
{
/* Lab 5 TODO Begin (TODO 4)*/
/* Lab 5 TODO Begin (Part 4)*/

/* Find the server_entry by client fd and client badge */

/* Decrement the server_entry refcnt */

/* If refcnt is 0, free the server_entry and decrement the vnode
* refcnt*/

return 0;
/* Lab 5 TODO End (TODO 4)*/
/* Lab 5 TODO End (Part 4)*/
}

int fs_wrapper_chmod(badge_t client_badge, ipc_msg_t *ipc_msg,
Expand All @@ -141,9 +165,13 @@ int fs_wrapper_chmod(badge_t client_badge, ipc_msg_t *ipc_msg,
static int __fs_wrapper_read_core(struct server_entry *server_entry, void *buf,
size_t size, off_t offset)
{
/* Lab 5 TODO Begin (TODO 4)*/
/* Lab 5 TODO Begin (Part 4)*/
/* Use server_ops to read the file into buf. */
/* Do check the boundary of the file and file permission correctly Check
* Posix Standard for further references. */
/* You also should update the offset of the server_entry offset */
return 0;
/* Lab 5 TODO End (TODO 4)*/
/* Lab 5 TODO End (Part 4)*/
}

int fs_wrapper_read(ipc_msg_t *ipc_msg, struct fs_request *fr)
Expand Down Expand Up @@ -220,9 +248,13 @@ int fs_wrapper_pread(ipc_msg_t *ipc_msg, struct fs_request *fr)
static int __fs_wrapper_write_core(struct server_entry *server_entry, void *buf,
size_t size, off_t offset)
{
/* Lab 5 TODO Begin (TODO 4)*/
/* Lab 5 TODO Begin (Part 4)*/
/* Use server_ops to write the file from buf. */
/* Do check the boundary of the file and file permission correctly Check
* Posix Standard for further references. */
/* You also should update the offset of the server_entry offset */
return 0;
/* Lab 5 TODO End (TODO 4)*/
/* Lab 5 TODO End (Part 4)*/
}

int fs_wrapper_pwrite(ipc_msg_t *ipc_msg, struct fs_request *fr)
Expand Down Expand Up @@ -336,9 +368,10 @@ int fs_wrapper_write(ipc_msg_t *ipc_msg, struct fs_request *fr)

int fs_wrapper_lseek(ipc_msg_t *ipc_msg, struct fs_request *fr)
{
/* Lab 5 TODO Begin (TODO 4)*/
/* Lab 5 TODO Begin (Part 4)*/
/* Check the posix standard. Adjust the server_entry content.*/
return 0;
/* Lab 5 TODO End (TODO 4)*/
/* Lab 5 TODO End (Part 4)*/
}

int fs_wrapper_ftruncate(ipc_msg_t *ipc_msg, struct fs_request *fr)
Expand Down Expand Up @@ -630,7 +663,8 @@ int fs_wrapper_fmap(badge_t client_badge, ipc_msg_t *ipc_msg,
}
}

/* Open flags do not check if a file can be executed so we check it again here */
/* Open flags do not check if a file can be executed so we check it
* again here */
if ((prot & PROT_EXEC) == PROT_EXEC) {
struct stat st;
ret = server_ops.fstatat(entry->path, &st, AT_SYMLINK_FOLLOW);
Expand Down Expand Up @@ -706,7 +740,8 @@ int fs_wrapper_fmap(badge_t client_badge, ipc_msg_t *ipc_msg,
int fs_wrapper_funmap(badge_t client_badge, ipc_msg_t *ipc_msg,
struct fs_request *fr)
{
return fmap_area_remove(client_badge, (vaddr_t)fr->munmap.addr, fr->munmap.length);
return fmap_area_remove(
client_badge, (vaddr_t)fr->munmap.addr, fr->munmap.length);
}

int fs_wrapper_creat(ipc_msg_t *ipc_msg, struct fs_request *fr)
Expand Down
76 changes: 63 additions & 13 deletions Lab5/user/system-services/system-servers/fsm/fsm.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* Licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS),
* Shanghai Jiao Tong University (SJTU) Licensed under the Mulan PSL v2. You can
* use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
* Mulan PSL v2 for more details.
*/

#include "fsm.h"
Expand Down Expand Up @@ -80,7 +80,8 @@ static int boot_tmpfs(void)
ipc_msg =
ipc_create_msg(procmgr_ipc_struct, sizeof(struct proc_request));
pr.req = PROC_REQ_GET_SERVICE_CAP;
strncpy(pr.get_service_cap.service_name, SERVER_TMPFS,
strncpy(pr.get_service_cap.service_name,
SERVER_TMPFS,
SERVICE_NAME_LEN);

ipc_set_msg_data(ipc_msg, &pr, 0, sizeof(pr));
Expand Down Expand Up @@ -144,7 +145,17 @@ int fsm_mount_fs(const char *path, const char *mount_point)
}

/* Lab 5 TODO Begin (Part 1) */
/* HINT: fsm has the ability to request page_cache syncing and mount and
* unmount request to the corresponding filesystem. Register an ipc client for each node*/

/* mp_node->_fs_ipc_struct = ipc_register_client(...) */

/* Increment the fs_num */

/* Set the correct return value */

UNUSED(mp_node);

pthread_rwlock_unlock(&mount_point_infos_rwlock);
/* Lab 5 TODO End (Part 1) */

Expand Down Expand Up @@ -236,9 +247,44 @@ DEFINE_SERVER_HANDLER(fsm_dispatch)
fsm_req = (struct fsm_request *)ipc_get_msg_data(ipc_msg);
switch (fsm_req->req) {
case FSM_REQ_PARSE_PATH: {
// Get Corresponding MOUNT_INFO
/* Lab 5 TODO Begin (Part 1) */

/* HINT: MountInfo is the info node that records each mount
* point and actual path*/
/* It also contains a ipc_client that delegates the actual
* filesystem. PARSE_PATH is the actual vfs layer that does the
* path traversing */
/* e.g. /mnt/ -> /dev/sda1 /mnt/1 -> /dev/sda2 */
/* You should use the get_mount_point function to get
* mount_info. for example get_mount_info will return
* mount_info(/mnt/1/123) node that represents /dev/sda2.*/
/* You should use get_mount_info to get the mount_info and set
* the fsm_req ipc_msg with mount_id*/

/* lock the mount_info with rdlock */

/* mpinfo = get_mount_point(..., ...) */

/* lock the client_cap_table with mutex */

/* mount_id = fsm_get_client_cap(...) */

/* if mount_id is not present, we first register the cap set the
* cap and get mount_id */

/* set the mount_id, mount_path, mount_path_len in the fsm_req
*/

/* Specifically if we register a new fs_cap in the cap_table, we
* should let the caller know with a fsm_req->new_cap_flag and
* then return fs_cap (noted above from mount_id) to the
* caller*/

/* Before returning to the caller , unlock the client_cap_table
* and mount_info_table */

UNUSED(mpinfo);

UNUSED(mount_id);
/* Lab 5 TODO End (Part 1) */
break;
Expand All @@ -258,8 +304,8 @@ DEFINE_SERVER_HANDLER(fsm_dispatch)
}
default:
error("%s: %d Not impelemented yet\n",
__func__,
((int *)(ipc_get_msg_data(ipc_msg)))[0]);
__func__,
((int *)(ipc_get_msg_data(ipc_msg)))[0]);
usys_exit(-1);
break;
}
Expand All @@ -270,7 +316,8 @@ DEFINE_SERVER_HANDLER(fsm_dispatch)
ipc_return(ipc_msg, ret);
}

static void* fsm_server_thread_for_itself(void* args){
static void *fsm_server_thread_for_itself(void *args)
{
info("[FSM] register server value = %u\n",
ipc_register_server_with_destructor(fsm_dispatch,
DEFAULT_CLIENT_REGISTER_HANDLER,
Expand All @@ -287,7 +334,10 @@ int main(int argc, char *argv[], char *envp[])
ipc_register_server_with_destructor(fsm_dispatch,
DEFAULT_CLIENT_REGISTER_HANDLER,
fsm_destructor));
server_cap = chcore_pthread_create(&fsm_server_thread_id, NULL, fsm_server_thread_for_itself, NULL);
server_cap = chcore_pthread_create(&fsm_server_thread_id,
NULL,
fsm_server_thread_for_itself,
NULL);
mount_disk_fs(server_cap);
usys_exit(0);
return 0;
Expand Down
Loading

0 comments on commit e01170e

Please sign in to comment.