[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4d00164c296166b682@agluck-desktop.sc.intel.com>
Date: Wed, 08 Dec 2010 15:35:40 -0800
From: "Luck, Tony" <tony.luck@...el.com>
To: linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org
Cc: tglx@...utronix.de, mingo@...e.hu, greg@...ah.com,
akpm@...ux-foundation.org, ying.huang@...el.com,
"Borislav Petkov" <bp@...en8.de>,
"David Miller" <davem@...emloft.net>,
"Alan Cox" <alan@...rguk.ukuu.org.uk>,
"Jim Keniston" <jkenisto@...ux.vnet.ibm.com>,
"Kyungmin Park" <kmpark@...radead.org>,
"Geert Uytterhoeven" <geert@...ux-m68k.org>
Subject: Re: [RFC] persistent store (version 3) (part 1 of 2)
> > what happens if it IS_ERR?
>
> Good point - I need to clean up if things fail (and akpm would
> like to see me re-factor so that there is only one "return"
> statement for better maintainabiliy). I'll fix up stuff here.
Here's what I'll have in the next version. With all the error
handling the pstore_mkfile() routine was getting a bit big, so
I split out the writing-to-the-file part into another function.
The pair of functions now look like this:
/*
* Set up a file structure as if we had opened this file and
* write our data to it.
*/
static int pstore_writefile(struct inode *inode, struct dentry *dentry,
char *data, size_t size)
{
struct file f;
ssize_t n;
mm_segment_t old_fs = get_fs();
memset(&f, '0', sizeof f);
f.f_mapping = inode->i_mapping;
f.f_path.dentry = dentry;
f.f_path.mnt = pstore_mnt;
f.f_pos = 0;
f.f_op = inode->i_fop;
set_fs(KERNEL_DS);
n = do_sync_write(&f, data, size, &f.f_pos);
set_fs(old_fs);
return n == size;
}
/*
* Make a regular file in the root directory of our file system.
* Load it up with "size" bytes of data from "buf".
* Set the mtime & ctime to the date that this record was originally stored.
*/
int pstore_mkfile(char *name, char *data, size_t size, struct timespec time,
void *private)
{
struct dentry *root = pstore_sb->s_root;
struct dentry *dentry;
struct inode *inode;
int rc = 0;
inode = pstore_get_inode(pstore_sb, root->d_inode, S_IFREG | 0444, 0);
if (!inode) {
rc = -ENOMEM;
goto fail;
}
inode->i_private = private;
mutex_lock(&root->d_inode->i_mutex);
dentry = d_alloc_name(root, name);
if (IS_ERR(dentry)) {
mutex_unlock(&root->d_inode->i_mutex);
rc = -ENOSPC;
goto fail1;
}
d_add(dentry, inode);
mutex_unlock(&root->d_inode->i_mutex);
if (!pstore_writefile(inode, dentry, data, size)) {
inode->i_nlink--;
mutex_lock(&root->d_inode->i_mutex);
d_delete(dentry);
dput(dentry);
mutex_unlock(&root->d_inode->i_mutex);
rc = -ENOSPC;
goto fail;
}
if (time.tv_sec)
inode->i_mtime = inode->i_ctime = time;
return 0;
fail1:
iput(inode);
fail:
return rc;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists