From 834fd6bd0ef8a0fadb4e361efff85f599dc73315 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Thu, 5 Nov 2026 15:56:18 +0100 Subject: [PATCH] classifier: Fix directory rule to match within correct filesystem Inode numbers are unique only within a filesystem, so i_ino alone matches directories on other filesystems. Add i_sb that tracks superblock pointer together with inode number, so that mountpoint on the path of classification rule does not lead to misclassification. Signed-off-by: Robert Baldyga --- modules/cas_cache/classifier.c | 8 ++++++-- modules/cas_cache/classifier_defs.h | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/cas_cache/classifier.c b/modules/cas_cache/classifier.c index 17a6834a7..8baaa5395 100644 --- a/modules/cas_cache/classifier.c +++ b/modules/cas_cache/classifier.c @@ -333,9 +333,11 @@ static void _cas_cls_directory_resolve(struct cas_classifier *cls, int error; int o_res; unsigned long o_ino; + const struct super_block *o_sb; o_res = ctx->resolved; o_ino = ctx->i_ino; + o_sb = ctx->i_sb; error = kern_path(ctx->pathname, LOOKUP_FOLLOW, &path); if (error) { @@ -349,13 +351,14 @@ static void _cas_cls_directory_resolve(struct cas_classifier *cls, inode = path.dentry->d_inode; ctx->i_ino = inode->i_ino; + ctx->i_sb = inode->i_sb; ctx->resolved = 1; path_put(&path); if (!o_res) { CAS_CLS_DEBUG_MSG("Resolved %s to inode: %lu\n", ctx->pathname, ctx->i_ino); - } else if (o_ino != ctx->i_ino) { + } else if (o_ino != ctx->i_ino || o_sb != ctx->i_sb) { CAS_CLS_DEBUG_MSG("Changed inode resolution for %s: %lu => %lu" "\n", ctx->pathname, o_ino, ctx->i_ino); } @@ -423,7 +426,8 @@ static cas_cls_eval_t _cas_cls_directory_test( dentry = _cas_cls_dir_get_inode_dentry(inode); for (depth = 0; dentry && depth < CAS_CLS_DIR_MAX_DEPTH; depth++) { d_ino = dentry->d_inode; - if (d_ino && d_ino->i_ino == ctx->i_ino) { + if (d_ino && d_ino->i_ino == ctx->i_ino && + d_ino->i_sb == ctx->i_sb) { result = cas_cls_eval_yes; break; } diff --git a/modules/cas_cache/classifier_defs.h b/modules/cas_cache/classifier_defs.h index a5feb2963..47c46d6a3 100644 --- a/modules/cas_cache/classifier_defs.h +++ b/modules/cas_cache/classifier_defs.h @@ -1,5 +1,6 @@ /* * Copyright(c) 2019-2021 Intel Corporation +* Copyright(c) 2026 Unvertical * SPDX-License-Identifier: BSD-3-Clause */ @@ -140,6 +141,9 @@ struct cas_cls_directory { /* Resolved inode */ unsigned long i_ino; + /* Superblock of resolved inode */ + const struct super_block *i_sb; + /* Back pointer to classifier context */ struct cas_classifier *cls;