Skip to content

Commit b2415d1

Browse files
LiBaokun96brauner
authored andcommitted
cachefiles: stop sending new request when dropping object
Added CACHEFILES_ONDEMAND_OBJSTATE_DROPPING indicates that the cachefiles object is being dropped, and is set after the close request for the dropped object completes, and no new requests are allowed to be sent after this state. This prepares for the later addition of cancel_work_sync(). It prevents leftover reopen requests from being sent, to avoid processing unnecessary requests and to avoid cancel_work_sync() blocking by waiting for daemon to complete the reopen requests. Signed-off-by: Baokun Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Jeff Layton <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Jia Zhu <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 0ece614 commit b2415d1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

fs/cachefiles/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum cachefiles_object_state {
4848
CACHEFILES_ONDEMAND_OBJSTATE_CLOSE, /* Anonymous fd closed by daemon or initial state */
4949
CACHEFILES_ONDEMAND_OBJSTATE_OPEN, /* Anonymous fd associated with object is available */
5050
CACHEFILES_ONDEMAND_OBJSTATE_REOPENING, /* Object that was closed and is being reopened. */
51+
CACHEFILES_ONDEMAND_OBJSTATE_DROPPING, /* Object is being dropped. */
5152
};
5253

5354
struct cachefiles_ondemand_info {
@@ -332,6 +333,7 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \
332333
CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN);
333334
CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE);
334335
CACHEFILES_OBJECT_STATE_FUNCS(reopening, REOPENING);
336+
CACHEFILES_OBJECT_STATE_FUNCS(dropping, DROPPING);
335337

336338
static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req)
337339
{

fs/cachefiles/ondemand.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object,
422422
*/
423423
xas_lock(&xas);
424424

425-
if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
425+
if (test_bit(CACHEFILES_DEAD, &cache->flags) ||
426+
cachefiles_ondemand_object_is_dropping(object)) {
426427
xas_unlock(&xas);
427428
ret = -EIO;
428429
goto out;
@@ -463,7 +464,8 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object,
463464
* If error occurs after creating the anonymous fd,
464465
* cachefiles_ondemand_fd_release() will set object to close.
465466
*/
466-
if (opcode == CACHEFILES_OP_OPEN)
467+
if (opcode == CACHEFILES_OP_OPEN &&
468+
!cachefiles_ondemand_object_is_dropping(object))
467469
cachefiles_ondemand_set_object_close(object);
468470
kfree(req);
469471
return ret;
@@ -562,8 +564,12 @@ int cachefiles_ondemand_init_object(struct cachefiles_object *object)
562564

563565
void cachefiles_ondemand_clean_object(struct cachefiles_object *object)
564566
{
567+
if (!object->ondemand)
568+
return;
569+
565570
cachefiles_ondemand_send_req(object, CACHEFILES_OP_CLOSE, 0,
566571
cachefiles_ondemand_init_close_req, NULL);
572+
cachefiles_ondemand_set_object_dropping(object);
567573
}
568574

569575
int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object,

0 commit comments

Comments
 (0)