From: David Howells <dhowells@redhat.com>
To: torvalds@osdl.org, akpm@osdl.org, sds@tycho.nsa.gov,
trond.myklebust@fys.uio.no
Cc: dhowells@redhat.com, selinux@tycho.nsa.gov,
linux-kernel@vger.kernel.org, aviro@redhat.com,
steved@redhat.com
Subject: [PATCH 18/19] CacheFiles: Use VFS lookup services
Date: Tue, 14 Nov 2006 20:07:00 +0000 [thread overview]
Message-ID: <20061114200700.12943.92679.stgit@warthog.cambridge.redhat.com> (raw)
In-Reply-To: <20061114200621.12943.18023.stgit@warthog.cambridge.redhat.com>
Make CacheFiles use the VFS's lookup services for each step of path resolution
rather than doing the hashing, dcache lookup and calling the inode lookup op
itself.
This is possible now that CacheFiles can temporarily override the security
context set by SELinux.
Signed-Off-By: David Howells <dhowells@redhat.com>
---
fs/cachefiles/cf-namei.c | 224 +++++++---------------------------------------
1 files changed, 34 insertions(+), 190 deletions(-)
diff --git a/fs/cachefiles/cf-namei.c b/fs/cachefiles/cf-namei.c
index 5508fa2..a3df94a 100644
--- a/fs/cachefiles/cf-namei.c
+++ b/fs/cachefiles/cf-namei.c
@@ -70,8 +70,7 @@ static int cachefiles_bury_object(struct
struct dentry *dir,
struct dentry *rep)
{
- struct dentry *grave, *alt, *trap;
- struct qstr name;
+ struct dentry *grave, *trap;
char nbuffer[8 + 8 + 1];
int ret;
@@ -103,23 +102,6 @@ try_again:
(uint32_t) xtime.tv_sec,
(uint32_t) atomic_inc_return(&cache->gravecounter));
- name.name = nbuffer;
- name.len = strlen(name.name);
-
- /* hash the name */
- name.hash = full_name_hash(name.name, name.len);
-
- if (dir->d_op && dir->d_op->d_hash) {
- ret = dir->d_op->d_hash(dir, &name);
- if (ret < 0) {
- if (ret == -EIO)
- cachefiles_io_error(cache, "Hash failed");
-
- _leave(" = %d", ret);
- return ret;
- }
- }
-
/* do the multiway lock magic */
trap = lock_rename(cache->graveyard, dir);
@@ -150,38 +132,18 @@ try_again:
return -EIO;
}
- /* see if there's a dentry already there for this name */
- grave = d_lookup(cache->graveyard, &name);
- if (!grave) {
- _debug("not found");
+ grave = lookup_one_len(nbuffer, cache->graveyard, strlen(nbuffer));
+ if (IS_ERR(grave)) {
+ unlock_rename(cache->graveyard, dir);
- grave = d_alloc(cache->graveyard, &name);
- if (!grave) {
- unlock_rename(cache->graveyard, dir);
+ if (PTR_ERR(grave) == -ENOMEM) {
_leave(" = -ENOMEM");
return -ENOMEM;
}
- alt = cache->graveyard->d_inode->i_op->lookup(
- cache->graveyard->d_inode, grave, NULL);
- if (IS_ERR(alt)) {
- unlock_rename(cache->graveyard, dir);
- dput(grave);
-
- if (PTR_ERR(alt) == -ENOMEM) {
- _leave(" = -ENOMEM");
- return -ENOMEM;
- }
-
- cachefiles_io_error(cache, "Lookup error %ld",
- PTR_ERR(alt));
- return -EIO;
- }
-
- if (alt) {
- dput(grave);
- grave = alt;
- }
+ cachefiles_io_error(cache, "Lookup error %ld",
+ PTR_ERR(grave));
+ return -EIO;
}
if (grave->d_inode) {
@@ -253,9 +215,9 @@ int cachefiles_walk_to_object(struct cac
struct cachefiles_xattr *auxdata)
{
struct cachefiles_cache *cache;
- struct dentry *dir, *next = NULL, *new;
- struct qstr name;
- int ret;
+ struct dentry *dir, *next = NULL;
+ char *name;
+ int ret, nlen;
_enter("{%p}", parent->dentry);
@@ -275,69 +237,24 @@ int cachefiles_walk_to_object(struct cac
advance:
/* attempt to transit the first directory component */
- name.name = key;
+ name = key;
key = strchr(key, '/');
if (key) {
- name.len = key - (char *) name.name;
+ nlen = key - name;
*key++ = 0;
} else {
- name.len = strlen(name.name);
- }
-
- /* hash the name */
- name.hash = full_name_hash(name.name, name.len);
-
- if (dir->d_op && dir->d_op->d_hash) {
- ret = dir->d_op->d_hash(dir, &name);
- if (ret < 0) {
- cachefiles_io_error(cache, "Hash failed");
- goto error_out2;
- }
+ nlen = strlen(name);
}
lookup_again:
/* search the current directory for the element name */
- _debug("lookup '%s' %x", name.name, name.hash);
+ _debug("lookup '%s'", name);
mutex_lock(&dir->d_inode->i_mutex);
- next = d_lookup(dir, &name);
- if (!next) {
- _debug("not found");
-
- new = d_alloc(dir, &name);
- if (!new)
- goto nomem_d_alloc;
-
- ASSERT(dir->d_inode->i_op);
- ASSERT(dir->d_inode->i_op->lookup);
-
- next = dir->d_inode->i_op->lookup(dir->d_inode, new, NULL);
- if (IS_ERR(next))
- goto lookup_error;
-
- if (!next)
- next = new;
- else
- dput(new);
-
- if (next->d_inode) {
- ret = -EPERM;
- if (!next->d_inode->i_op ||
- !next->d_inode->i_op->setxattr ||
- !next->d_inode->i_op->getxattr ||
- !next->d_inode->i_op->removexattr)
- goto error;
-
- if (key && (!next->d_inode->i_op->lookup ||
- !next->d_inode->i_op->mkdir ||
- !next->d_inode->i_op->create ||
- !next->d_inode->i_op->rename ||
- !next->d_inode->i_op->rmdir ||
- !next->d_inode->i_op->unlink))
- goto error;
- }
- }
+ next = lookup_one_len(name, dir, nlen);
+ if (IS_ERR(next))
+ goto lookup_error;
_debug("next -> %p %s", next, next->d_inode ? "positive" : "negative");
@@ -496,15 +413,10 @@ delete_error:
lookup_error:
_debug("lookup error %ld", PTR_ERR(next));
- dput(new);
ret = PTR_ERR(next);
if (ret == -EIO)
cachefiles_io_error(cache, "Lookup failed");
next = NULL;
- goto error;
-
-nomem_d_alloc:
- ret = -ENOMEM;
error:
mutex_unlock(&dir->d_inode->i_mutex);
dput(next);
@@ -525,48 +437,19 @@ struct dentry *cachefiles_get_directory(
struct dentry *dir,
const char *dirname)
{
- struct dentry *subdir, *new;
- struct qstr name;
+ struct dentry *subdir;
int ret;
- _enter("");
-
- /* set up the name */
- name.name = dirname;
- name.len = strlen(dirname);
- name.hash = full_name_hash(name.name, name.len);
-
- if (dir->d_op && dir->d_op->d_hash) {
- ret = dir->d_op->d_hash(dir, &name);
- if (ret < 0) {
- if (ret == -EIO)
- kerror("Hash failed");
- _leave(" = %d", ret);
- return ERR_PTR(ret);
- }
- }
+ _enter(",,%s", dirname);
/* search the current directory for the element name */
- _debug("lookup '%s' %x", name.name, name.hash);
-
mutex_lock(&dir->d_inode->i_mutex);
- subdir = d_lookup(dir, &name);
- if (!subdir) {
- _debug("not found");
-
- new = d_alloc(dir, &name);
- if (!new)
+ subdir = lookup_one_len(dirname, dir, strlen(dirname));
+ if (IS_ERR(subdir)) {
+ if (PTR_ERR(subdir) == -ENOMEM)
goto nomem_d_alloc;
-
- subdir = dir->d_inode->i_op->lookup(dir->d_inode, new, NULL);
- if (IS_ERR(subdir))
- goto lookup_error;
-
- if (!subdir)
- subdir = new;
- else
- dput(new);
+ goto lookup_error;
}
_debug("subdir -> %p %s",
@@ -578,6 +461,8 @@ struct dentry *cachefiles_get_directory(
if (ret < 0)
goto mkdir_error;
+ _debug("attempt mkdir");
+
ret = vfs_mkdir(dir->d_inode, subdir, 0700);
if (ret < 0)
goto mkdir_error;
@@ -625,23 +510,18 @@ mkdir_error:
mutex_unlock(&dir->d_inode->i_mutex);
dput(subdir);
kerror("mkdir %s failed with error %d", dirname, ret);
- goto error_out;
+ return ERR_PTR(ret);
lookup_error:
mutex_unlock(&dir->d_inode->i_mutex);
- dput(new);
ret = PTR_ERR(subdir);
kerror("Lookup %s failed with error %d", dirname, ret);
- goto error_out;
+ return ERR_PTR(ret);
nomem_d_alloc:
mutex_unlock(&dir->d_inode->i_mutex);
- ret = -ENOMEM;
- goto error_out;
-
-error_out:
- _leave(" = %d", ret);
- return ERR_PTR(ret);
+ _leave(" = -ENOMEM");
+ return ERR_PTR(-ENOMEM);
}
/*
@@ -653,48 +533,18 @@ int cachefiles_cull(struct cachefiles_ca
{
struct cachefiles_object *object;
struct rb_node *_n;
- struct dentry *victim, *new;
- struct qstr name;
+ struct dentry *victim;
int ret;
_enter(",%*.*s/,%s",
dir->d_name.len, dir->d_name.len, dir->d_name.name, filename);
- /* set up the name */
- name.name = filename;
- name.len = strlen(filename);
- name.hash = full_name_hash(name.name, name.len);
-
- if (dir->d_op && dir->d_op->d_hash) {
- ret = dir->d_op->d_hash(dir, &name);
- if (ret < 0) {
- if (ret == -EIO)
- cachefiles_io_error(cache, "Hash failed");
- _leave(" = %d", ret);
- return ret;
- }
- }
-
/* look up the victim */
mutex_lock(&dir->d_inode->i_mutex);
- victim = d_lookup(dir, &name);
- if (!victim) {
- _debug("not found");
-
- new = d_alloc(dir, &name);
- if (!new)
- goto nomem_d_alloc;
-
- victim = dir->d_inode->i_op->lookup(dir->d_inode, new, NULL);
- if (IS_ERR(victim))
- goto lookup_error;
-
- if (!victim)
- victim = new;
- else
- dput(new);
- }
+ victim = lookup_one_len(filename, dir, strlen(filename));
+ if (IS_ERR(victim))
+ goto lookup_error;
_debug("victim -> %p %s",
victim, victim->d_inode ? "positive" : "negative");
@@ -755,14 +605,8 @@ object_in_use:
_leave(" = -EBUSY [in use]");
return -EBUSY;
-nomem_d_alloc:
- mutex_unlock(&dir->d_inode->i_mutex);
- _leave(" = -ENOMEM");
- return -ENOMEM;
-
lookup_error:
mutex_unlock(&dir->d_inode->i_mutex);
- dput(new);
ret = PTR_ERR(victim);
if (ret == -EIO)
cachefiles_io_error(cache, "Lookup failed");
next prev parent reply other threads:[~2006-11-14 20:12 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-14 20:06 [PATCH 00/19] Permit filesystem local caching and NFS superblock sharing David Howells
2006-11-14 20:06 ` [PATCH 02/19] FS-Cache: Provide a filesystem-specific sync'able page bit David Howells
2006-11-14 20:06 ` [PATCH 03/19] FS-Cache: Release page->private after failed readahead David Howells
2006-11-14 20:06 ` [PATCH 04/19] FS-Cache: Make kAFS use FS-Cache David Howells
2006-11-14 20:06 ` [PATCH 05/19] NFS: Use local caching David Howells
2006-11-15 12:38 ` Steve Dickson
2006-11-15 15:09 ` Trond Myklebust
2006-11-15 16:00 ` David Howells
2006-11-15 16:52 ` Trond Myklebust
2006-11-15 17:07 ` David Howells
2006-11-15 17:53 ` Trond Myklebust
2006-11-14 20:06 ` [PATCH 06/19] FS-Cache: NFS: Only obtain cache cookies on file open, not on inode read David Howells
2006-11-15 11:23 ` Steve Dickson
2006-11-14 20:06 ` [PATCH 07/19] CacheFiles: Add missing copy_page export for ia64 David Howells
2006-11-14 20:06 ` [PATCH 08/19] CacheFiles: Add a function to write a single page of data to an inode David Howells
2006-11-14 20:06 ` [PATCH 09/19] CacheFiles: Permit the page lock state to be monitored David Howells
2006-11-14 20:06 ` [PATCH 10/19] CacheFiles: Export things for CacheFiles David Howells
2006-11-14 20:06 ` [PATCH 12/19] CacheFiles: Permit a process's create SID to be overridden David Howells
2006-11-14 21:19 ` James Morris
2006-11-20 18:41 ` Stephen Smalley
2006-11-20 19:56 ` Karl MacMillan
2006-11-20 22:29 ` James Morris
2006-11-15 12:26 ` David Howells
2006-11-15 16:19 ` James Morris
2006-11-15 16:23 ` David Howells
2006-11-15 17:52 ` Karl MacMillan
2006-11-15 18:21 ` David Howells
2006-11-20 18:49 ` Stephen Smalley
2006-11-15 19:09 ` David Howells
2006-11-15 19:11 ` David Howells
2006-11-15 13:50 ` David Howells
2006-11-15 16:22 ` James Morris
2006-11-15 17:54 ` Karl MacMillan
2006-11-14 20:06 ` [PATCH 13/19] CacheFiles: Add an act-as SID override in task_security_struct David Howells
2006-11-14 20:06 ` [PATCH 14/19] CacheFiles: Permit an inode's security ID to be obtained David Howells
2006-11-14 20:06 ` [PATCH 15/19] CacheFiles: Get the SID under which the CacheFiles module should operate David Howells
2006-11-14 20:06 ` [PATCH 16/19] CacheFiles: Deal with LSM when accessing the cache David Howells
2006-11-14 21:27 ` James Morris
2006-11-14 20:06 ` [PATCH 17/19] CacheFiles: Use the VFS wrappers for inode ops David Howells
2006-11-14 20:07 ` David Howells [this message]
2006-11-14 20:07 ` [PATCH 19/19] CacheFiles: Permit daemon to probe inuseness of a cache file David Howells
2006-11-15 15:52 ` Christoph Hellwig
2006-11-15 16:10 ` David Howells
2006-11-15 10:10 ` [PATCH 20/19] CacheFiles: Use secid not sid lest confusion arise with session IDs David Howells
2006-11-15 13:17 ` [PATCH 21/19] CacheFiles: Set the file creation security ID whilst binding the cache David Howells
2006-11-15 13:23 ` [PATCH 22/19] FS-Cache: NFS: Rename NFS_INO_CACHEABLE David Howells
2006-11-15 16:42 ` [PATCH 23/19] FS-Cache: NFS: Don't invoke FS-Cache from nfs_zap_caches() David Howells
2006-11-15 16:51 ` [PATCH 24/19] FS-Cache: NFS: Remove old support for R/W caching David Howells
2006-11-15 17:22 ` [PATCH 25/19] FS-Cache: NFS: Wait in releasepage() if FS-Cache is busy and __GFP_WAIT is set David Howells
2006-11-17 10:01 ` [PATCH 26/19] CacheFiles: Don't include linux/proc_fs.h David Howells
2006-11-23 13:10 ` [PATCH 27/19] FS-Cache: Apply the PG_checked -> PG_fs_misc conversion to Ext4 David Howells
2006-11-23 13:17 ` [PATCH 28/19] FS-Cache: NFS: Handle caching being disabled correctly David Howells
2006-11-23 20:13 ` [PATCH 29/19] CacheFiles: Remove old obsolete cull function David Howells
2006-11-29 16:47 ` [PATCH 30/19] CacheFiles: Fix the allocate_page() op David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061114200700.12943.92679.stgit@warthog.cambridge.redhat.com \
--to=dhowells@redhat.com \
--cc=akpm@osdl.org \
--cc=aviro@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
--cc=steved@redhat.com \
--cc=torvalds@osdl.org \
--cc=trond.myklebust@fys.uio.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome