From 52aeb442bc4c3cc6e174222e436378d0ab8fe312 Mon Sep 17 00:00:00 2001 From: zhangkaixiang Date: Sun, 9 Oct 2022 03:52:56 +0000 Subject: [PATCH] add the num of share file Signed-off-by: zhangkaixiang --- fs/hmdfs/hmdfs_share.c | 32 +++++++++++++++++++++++++++++--- fs/hmdfs/hmdfs_share.h | 3 ++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/fs/hmdfs/hmdfs_share.c b/fs/hmdfs/hmdfs_share.c index 760afcbcec11..c8314a5d7fca 100644 --- a/fs/hmdfs/hmdfs_share.c +++ b/fs/hmdfs/hmdfs_share.c @@ -83,8 +83,11 @@ int insert_share_item(struct hmdfs_share_table *st, struct qstr *relative_path, int err = 0; if (st->item_cnt >= st->max_cnt) { - err = -EMFILE; - goto err_out; + int ret = hmdfs_clear_first_item(st); + if (unlikely(ret)) { + err = -EMFILE; + goto err_out; + } } path_name = kzalloc(PATH_MAX, GFP_KERNEL); @@ -245,15 +248,23 @@ void hmdfs_close_share_item(struct hmdfs_sb_info *sbi, struct file *file, goto unlock; } + /* + * If the item is shared to all device, we should close the item directly. + */ + if (!strcmp(item->cid, SHARE_ALL_DEVICE)) { + goto close; + } + if (unlikely(!is_dst_device(item->cid, cid))) { hmdfs_err("item not right, dst cid is: %s", item->cid); goto unlock; } /* - * After remote close, we shoule reset the opened status and restart + * After remote close, we should reset the opened status and restart * delayed timeout work. */ +close: item->opened = false; queue_delayed_work(item->hst->share_item_timeout_wq, &item->d_work, HZ * HMDFS_SHARE_ITEM_TIMEOUT_S); @@ -316,3 +327,18 @@ void hmdfs_clear_share_table(struct hmdfs_sb_info *sbi) destroy_workqueue(st->share_item_timeout_wq); } + +int hmdfs_clear_first_item(struct hmdfs_share_table *st) +{ + int ret = -EMFILE; + struct hmdfs_share_item *item, *tmp; + list_for_each_entry_safe(item, tmp, &st->item_list_head, list) { + if (!item->timeout) { + cancel_delayed_work_sync(&item->d_work); + } + remove_and_release_share_item(item); + ret = 0; + break; + } + return ret; +} diff --git a/fs/hmdfs/hmdfs_share.h b/fs/hmdfs/hmdfs_share.h index 8b1ecb29c6b8..eef53bf19bab 100644 --- a/fs/hmdfs/hmdfs_share.h +++ b/fs/hmdfs/hmdfs_share.h @@ -16,7 +16,7 @@ #include "comm/connection.h" #define HMDFS_SHARE_ITEM_TIMEOUT_S 120 -#define HMDFS_SHARE_ITEMS_MAX 4 +#define HMDFS_SHARE_ITEMS_MAX 128 #define HMDFS_IOC 0xf2 #define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, \ @@ -62,5 +62,6 @@ int hmdfs_check_share_access_permission(struct hmdfs_sb_info *sbi, void hmdfs_init_share_table(struct hmdfs_sb_info *sbi); void hmdfs_clear_share_table(struct hmdfs_sb_info *sbi); +int hmdfs_clear_first_item(struct hmdfs_share_table *st); #endif // HMDFS_SHARE_H -- Gitee