Skip to content

Commit 880bd49

Browse files
amir73ilpcmoore
authored andcommitted
fs: prepare for adding LSM blob to backing_file
In preparation to adding LSM blob to backing_file struct, factor out helpers init_backing_file() and backing_file_free(). Cc: stable@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-unionfs@vger.kernel.org Cc: linux-erofs@lists.ozlabs.org Signed-off-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Serge Hallyn <serge@hallyn.com> [PM: use the term "LSM blob", fix comment style to match file] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent d1a0919 commit 880bd49

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

fs/file_table.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,20 @@ void backing_file_set_user_path(struct file *f, const struct path *path)
6666
}
6767
EXPORT_SYMBOL_GPL(backing_file_set_user_path);
6868

69+
static inline void backing_file_free(struct backing_file *ff)
70+
{
71+
path_put(&ff->user_path);
72+
kmem_cache_free(bfilp_cachep, ff);
73+
}
74+
6975
static inline void file_free(struct file *f)
7076
{
7177
security_file_free(f);
7278
if (likely(!(f->f_mode & FMODE_NOACCOUNT)))
7379
percpu_counter_dec(&nr_files);
7480
put_cred(f->f_cred);
7581
if (unlikely(f->f_mode & FMODE_BACKING)) {
76-
path_put(backing_file_user_path(f));
77-
kmem_cache_free(bfilp_cachep, backing_file(f));
82+
backing_file_free(backing_file(f));
7883
} else {
7984
kmem_cache_free(filp_cachep, f);
8085
}
@@ -283,6 +288,12 @@ struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred)
283288
return f;
284289
}
285290

291+
static int init_backing_file(struct backing_file *ff)
292+
{
293+
memset(&ff->user_path, 0, sizeof(ff->user_path));
294+
return 0;
295+
}
296+
286297
/*
287298
* Variant of alloc_empty_file() that allocates a backing_file container
288299
* and doesn't check and modify nr_files.
@@ -305,7 +316,14 @@ struct file *alloc_empty_backing_file(int flags, const struct cred *cred)
305316
return ERR_PTR(error);
306317
}
307318

319+
/* The f_mode flags must be set before fput(). */
308320
ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT;
321+
error = init_backing_file(ff);
322+
if (unlikely(error)) {
323+
fput(&ff->file);
324+
return ERR_PTR(error);
325+
}
326+
309327
return &ff->file;
310328
}
311329
EXPORT_SYMBOL_GPL(alloc_empty_backing_file);

0 commit comments

Comments
 (0)