/*
* Copyright (C) 2005, 2006
* Avishay Traeger (avishay@gmail.com)
* Copyright (C) 2008, 2009
* Boaz Harrosh <bharrosh@panasas.com>
*
* Copyrights for code taken from ext2:
* Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr)
* Laboratoire MASI - Institut Blaise Pascal
* Universite Pierre et Marie Curie (Paris VI)
* from
* linux/fs/minix/inode.c
* Copyright (C) 1991, 1992 Linus Torvalds
*
* This file is part of exofs.
*
* exofs is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation. Since it is based on ext2, and the only
* valid version of GPL for the Linux kernel is version 2, the only valid
* version of GPL for exofs is version 2.
*
* exofs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with exofs; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <linux/string.h>
#include <linux/parser.h>
#include <linux/vfs.h>
#include <linux/random.h>
#include <linux/module.h>
#include <linux/exportfs.h>
#include <linux/slab.h>
#include "exofs.h"
#define EXOFS_DBGMSG2(M...) do {} while (0)
/******************************************************************************
* MOUNT OPTIONS
*****************************************************************************/
/*
* struct to hold what we get from mount options
*/
struct exofs_mountopt {
bool is_osdname;
const char *dev_name;
uint64_t pid;
int timeout;
};
/*
* exofs-specific mount-time options.
*/
enum { Opt_name, Opt_pid, Opt_to, Opt_err };
/*
* Our mount-time options. These should ideally be 64-bit unsigned, but the
* kernel's parsing functions do not currently support that. 32-bit should be
* sufficient for most applications now.
*/
static match_table_t tokens = {
{Opt_name, "osdname=%s"},
{Opt_pid, "pid=%u"},
{Opt_to, "to=%u"},
{Opt_err, NULL}
};
/*
* The main option parsing method. Also makes sure that all of the mandatory
* mount options were set.
*/
static int parse_options(char *options, struct exofs_mountopt *opts)
{
char *p;
substring_t args[MAX_OPT_ARGS];
int option;
bool s_pid = false;
EXOFS_DBGMSG("parse_options %s\n", options);
/* defaults */
memset(opts, 0, sizeof(*opts));
opts->timeout = BLK_DEFAULT_SG_TIMEOUT;
while ((p = strsep(&options, ",")) != NULL) {
int token;
char str[32];
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case Opt_name:
opts->dev_name = match_strdup(&args[0]);
if (unlikely(!opts->dev_name)) {
EXOFS_ERR("Error allocating dev_name");
return -ENOMEM;
}
opts->is_osdname = true;
break;
case Opt_pid:
if (0 == match_strlcpy(str, &args[0], sizeof(str)))
return -EINVAL;
opts->pid = simple_strtoull(str, NULL, 0);
if (opts->pid < EXOFS_MIN_PID) {
EXOFS_ERR("Partition ID must be >= %u",
EXOFS_MIN_PID);
return -EINVAL;
}
s_pid = 1;
break;
case Opt_to:
if (match_int(&args[0], &option))
return -EINVAL;
if (option <= 0) {
EXOFS_ERR("Timout must be > 0");
return -EINVAL;
}
opts->timeout = option * HZ;
break;
}
}
if (!s_pid) {
EXOFS_ERR("Need to specify the following options:\n");
EXOFS_ERR(" -o pid=pid_no_to_use\n");
return -EINVAL;
}
return 0;
}
/******************************************************************************
* INODE CACHE
*****************************************************************************/
/*
* Our inode cache. Isn't it pretty?
*/
static struct kmem_cache *exofs_inode_cachep;
/*
* Allocate an inode in the cache
*/
static struct inode *exofs_alloc_inode(struct super_block *sb)
{
struct exofs_i_info *oi;
oi = kmem_cache_alloc(exofs_inode_cachep, GFP_KERNEL);
if (!oi)
return NULL;
oi->vfs_inode.i_version = 1;
return &oi->vfs_inode;
}
static void exofs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
kmem_cache_free(exofs_inode_cachep, exofs_i(inode));
}
/*
* Remove an inode from the cache
*/
static void exofs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, exofs_i_callback);
}
/*
* Initialize the inode