fs/smb/client/dfs_cache.c
Source file repositories/reference/linux-study-clean/fs/smb/client/dfs_cache.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/client/dfs_cache.c- Extension
.c- Size
- 31898 bytes
- Lines
- 1357
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/jhash.hlinux/ktime.hlinux/slab.hlinux/proc_fs.hlinux/nls.hlinux/workqueue.hlinux/uuid.hcifsglob.hsmb2pdu.hsmb2proto.hcifsproto.hcifs_debug.hcifs_unicode.hsmb2glob.hdns_resolve.hdfs.hdfs_cache.h
Detected Declarations
struct cache_dfs_tgtstruct cache_entryfunction cache_entry_expiredfunction free_tgtsfunction list_for_each_entry_safefunction flush_cache_entfunction flush_cache_entsfunction hlist_for_each_entry_safefunction dfscache_proc_showfunction hlist_for_each_entryfunction list_for_each_entryfunction dfscache_proc_writefunction dfscache_proc_openfunction dump_tgtsfunction dump_cefunction dump_refsfunction dfs_cache_initfunction cache_entry_hashfunction get_expire_timefunction copy_ref_datafunction purge_cachefunction hlist_for_each_entry_safefunction dfs_path_equalfunction hlist_for_each_entryfunction ERR_PTRfunction dfs_cache_destroyfunction update_cache_entry_lockedfunction get_dfs_referralfunction setup_referralfunction get_targetsfunction list_for_each_entryfunction get_dfs_referfunction dfs_cache_noreq_findfunction dfs_cache_noreq_update_tgthintfunction list_for_each_entryfunction iteratorfunction dfs_cache_get_tgt_sharefunction target_share_equalfunction is_ses_goodfunction refresh_ses_referralfunction __refresh_tcon_referralfunction refresh_tcon_referralfunction dfs_cache_remount_fsfunction dfs_cache_refresh
Annotated Snippet
struct cache_dfs_tgt {
char *name;
int path_consumed;
struct list_head list;
};
struct cache_entry {
struct hlist_node hlist;
const char *path;
int hdr_flags; /* RESP_GET_DFS_REFERRAL.ReferralHeaderFlags */
int ttl; /* DFS_REREFERRAL_V3.TimeToLive */
int srvtype; /* DFS_REREFERRAL_V3.ServerType */
int ref_flags; /* DFS_REREFERRAL_V3.ReferralEntryFlags */
struct timespec64 etime;
int path_consumed; /* RESP_GET_DFS_REFERRAL.PathConsumed */
int numtgts;
struct list_head tlist;
struct cache_dfs_tgt *tgthint;
};
static struct kmem_cache *cache_slab __read_mostly;
struct workqueue_struct *dfscache_wq;
atomic_t dfs_cache_ttl;
static struct nls_table *cache_cp;
/*
* Number of entries in the cache
*/
static atomic_t cache_count;
static struct hlist_head cache_htable[CACHE_HTABLE_SIZE];
static DECLARE_RWSEM(htable_rw_lock);
/**
* dfs_cache_canonical_path - get a canonical DFS path
*
* @path: DFS path
* @cp: codepage
* @remap: mapping type
*
* Return canonical path if success, otherwise error.
*/
char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp, int remap)
{
char *tmp;
int plen = 0;
char *npath;
if (!path || strlen(path) < 3 || (*path != '\\' && *path != '/'))
return ERR_PTR(-EINVAL);
if (unlikely(strcmp(cp->charset, cache_cp->charset))) {
tmp = (char *)cifs_strndup_to_utf16(path, strlen(path), &plen, cp, remap);
if (!tmp) {
cifs_dbg(VFS, "%s: failed to convert path to utf16\n", __func__);
return ERR_PTR(-EINVAL);
}
npath = cifs_strndup_from_utf16(tmp, plen, true, cache_cp);
kfree(tmp);
if (!npath) {
cifs_dbg(VFS, "%s: failed to convert path from utf16\n", __func__);
return ERR_PTR(-EINVAL);
}
} else {
npath = kstrdup(path, GFP_KERNEL);
if (!npath)
return ERR_PTR(-ENOMEM);
}
convert_delimiter(npath, '\\');
return npath;
}
static inline bool cache_entry_expired(const struct cache_entry *ce)
{
struct timespec64 ts;
ktime_get_coarse_real_ts64(&ts);
return timespec64_compare(&ts, &ce->etime) >= 0;
}
static inline void free_tgts(struct cache_entry *ce)
{
struct cache_dfs_tgt *t, *n;
list_for_each_entry_safe(t, n, &ce->tlist, list) {
list_del(&t->list);
Annotation
- Immediate include surface: `linux/jhash.h`, `linux/ktime.h`, `linux/slab.h`, `linux/proc_fs.h`, `linux/nls.h`, `linux/workqueue.h`, `linux/uuid.h`, `cifsglob.h`.
- Detected declarations: `struct cache_dfs_tgt`, `struct cache_entry`, `function cache_entry_expired`, `function free_tgts`, `function list_for_each_entry_safe`, `function flush_cache_ent`, `function flush_cache_ents`, `function hlist_for_each_entry_safe`, `function dfscache_proc_show`, `function hlist_for_each_entry`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.