cregit-Linux how code gets into the kernel

Release 4.11 fs/exofs/super.c

Directory: fs/exofs
/*
 * Copyright (C) 2005, 2006
 * Avishay Traeger (avishay@gmail.com)
 * Copyright (C) 2008, 2009
 * Boaz Harrosh <ooo@electrozaur.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("Timeout 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; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh29199.66%266.67%
Masanari Iida10.34%133.33%
Total292100.00%3100.00%

/****************************************************************************** * 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; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh49100.00%1100.00%
Total49100.00%1100.00%


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)); }

Contributors

PersonTokensPropCommitsCommitProp
Nicholas Piggin36100.00%1100.00%
Total36100.00%1100.00%

/* * Remove an inode from the cache */
static void exofs_destroy_inode(struct inode *inode) { call_rcu(&inode->i_rcu, exofs_i_callback); }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh1571.43%150.00%
Nicholas Piggin628.57%150.00%
Total21100.00%2100.00%

/* * Initialize the inode */
static void exofs_init_once(void *foo) { struct exofs_i_info *oi = foo; inode_init_once(&oi->vfs_inode); }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh25100.00%1100.00%
Total25100.00%1100.00%

/* * Create and initialize the inode cache */
static int init_inodecache(void) { exofs_inode_cachep = kmem_cache_create("exofs_inode_cache", sizeof(struct exofs_i_info), 0, SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD | SLAB_ACCOUNT, exofs_init_once); if (exofs_inode_cachep == NULL) return -ENOMEM; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh4295.45%150.00%
Vladimir Davydov24.55%150.00%
Total44100.00%2100.00%

/* * Destroy the inode cache */
static void destroy_inodecache(void) { /* * Make sure all delayed rcu free inodes are flushed before we * destroy cache. */ rcu_barrier(); kmem_cache_destroy(exofs_inode_cachep); }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh1376.47%150.00%
Kirill A. Shutemov423.53%150.00%
Total17100.00%2100.00%

/****************************************************************************** * Some osd helpers *****************************************************************************/
void exofs_make_credential(u8 cred_a[OSD_CAP_LEN], const struct osd_obj_id *obj) { osd_sec_init_nosec_doall_caps(cred_a, obj, false, true); }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh28100.00%2100.00%
Total28100.00%2100.00%


static int exofs_read_kern(struct osd_dev *od, u8 *cred, struct osd_obj_id *obj, u64 offset, void *p, unsigned length) { struct osd_request *or = osd_start_request(od, GFP_KERNEL); /* struct osd_sense_info osi = {.key = 0};*/ int ret; if (unlikely(!or)) { EXOFS_DBGMSG("%s: osd_start_request failed.\n", __func__); return -ENOMEM; } ret = osd_req_read_kern(or, obj, offset, p, length); if (unlikely(ret)) { EXOFS_DBGMSG("%s: osd_req_read_kern failed.\n", __func__); goto out; } ret = osd_finalize_request(or, 0, cred, NULL); if (unlikely(ret)) { EXOFS_DBGMSG("Failed to osd_finalize_request() => %d\n", ret); goto out; } ret = osd_execute_request(or); if (unlikely(ret)) EXOFS_DBGMSG("osd_execute_request() => %d\n", ret); /* osd_req_decode_sense(or, ret); */ out: osd_end_request(or); EXOFS_DBGMSG2("read_kern(0x%llx) offset=0x%llx " "length=0x%llx dev=%p ret=>%d\n", _LLU(obj->id), _LLU(offset), _LLU(length), od, ret); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh192100.00%2100.00%
Total192100.00%2100.00%

static const struct osd_attr g_attr_sb_stats = ATTR_DEF( EXOFS_APAGE_SB_DATA, EXOFS_ATTR_SB_STATS, sizeof(struct exofs_sb_stats));
static int __sbi_read_stats(struct exofs_sb_info *sbi) { struct osd_attr attrs[] = { [0] = g_attr_sb_stats, }; struct ore_io_state *ios; int ret; ret = ore_get_io_state(&sbi->layout, &sbi->oc, &ios); if (unlikely(ret)) { EXOFS_ERR("%s: ore_get_io_state failed.\n", __func__); return ret; } ios->in_attr = attrs; ios->in_attr_len = ARRAY_SIZE(attrs); ret = ore_read(ios); if (unlikely(ret)) { EXOFS_ERR("Error reading super_block stats => %d\n", ret); goto out; } ret = extract_attr_from_ios(ios, &attrs[0]); if (ret) { EXOFS_ERR("%s: extract_attr of sb_stats failed\n", __func__); goto out; } if (attrs[0].len) { struct exofs_sb_stats *ess; if (unlikely(attrs[0].len != sizeof(*ess))) { EXOFS_ERR("%s: Wrong version of exofs_sb_stats " "size(%d) != expected(%zd)\n", __func__, attrs[0].len, sizeof(*ess)); goto out; } ess = attrs[0].val_ptr; sbi->s_nextid = le64_to_cpu(ess->s_nextid); sbi->s_numfiles = le32_to_cpu(ess->s_numfiles); } out: ore_put_io_state(ios); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh240100.00%4100.00%
Total240100.00%4100.00%


static void stats_done(struct ore_io_state *ios, void *p) { ore_put_io_state(ios); /* Good thanks nothing to do anymore */ }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh21100.00%2100.00%
Total21100.00%2100.00%

/* Asynchronously write the stats attribute */
int exofs_sbi_write_stats(struct exofs_sb_info *sbi) { struct osd_attr attrs[] = { [0] = g_attr_sb_stats, }; struct ore_io_state *ios; int ret; ret = ore_get_io_state(&sbi->layout, &sbi->oc, &ios); if (unlikely(ret)) { EXOFS_ERR("%s: ore_get_io_state failed.\n", __func__); return ret; } sbi->s_ess.s_nextid = cpu_to_le64(sbi->s_nextid); sbi->s_ess.s_numfiles = cpu_to_le64(sbi->s_numfiles); attrs[0].val_ptr = &sbi->s_ess; ios->done = stats_done; ios->private = sbi; ios->out_attr = attrs; ios->out_attr_len = ARRAY_SIZE(attrs); ret = ore_write(ios); if (unlikely(ret)) { EXOFS_ERR("%s: ore_write failed.\n", __func__); ore_put_io_state(ios); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh164100.00%4100.00%
Total164100.00%4100.00%

/****************************************************************************** * SUPERBLOCK FUNCTIONS *****************************************************************************/ static const struct super_operations exofs_sops; static const struct export_operations exofs_export_ops; /* * Write the superblock to the OSD */
static int exofs_sync_fs(struct super_block *sb, int wait) { struct exofs_sb_info *sbi; struct exofs_fscb *fscb; struct ore_comp one_comp; struct ore_components oc; struct ore_io_state *ios; int ret = -ENOMEM; fscb = kmalloc(sizeof(*fscb), GFP_KERNEL); if (unlikely(!fscb)) return -ENOMEM; sbi = sb->s_fs_info; /* NOTE: We no longer dirty the super_block anywhere in exofs. The * reason we write the fscb here on unmount is so we can stay backwards * compatible with fscb->s_version == 1. (What we are not compatible * with is if a new version FS crashed and then we try to mount an old * version). Otherwise the exofs_fscb is read-only from mkfs time. All * the writeable info is set in exofs_sbi_write_stats() above. */ exofs_init_comps(&oc, &one_comp, sbi, EXOFS_SUPER_ID); ret = ore_get_io_state(&sbi->layout, &oc, &ios); if (unlikely(ret)) goto out; ios->length = offsetof(struct exofs_fscb, s_dev_table_oid); memset(fscb, 0, ios->length); fscb->s_nextid = cpu_to_le64(sbi->s_nextid); fscb->s_numfiles = cpu_to_le64(sbi->s_numfiles); fscb->s_magic = cpu_to_le16(sb->s_magic); fscb->s_newfs = 0; fscb->s_version = EXOFS_FSCB_VER; ios->offset = 0; ios->kern_buff = fscb; ret = ore_write(ios); if (unlikely(ret)) EXOFS_ERR("%s: ore_write failed.\n", __func__); out: EXOFS_DBGMSG("s_nextid=0x%llx ret=%d\n", _LLU(sbi->s_nextid), ret); ore_put_io_state(ios); kfree(fscb); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh22692.62%866.67%
Christoph Hellwig166.56%216.67%
Dan Carpenter10.41%18.33%
H Hartley Sweeten10.41%18.33%
Total244100.00%12100.00%


static void _exofs_print_device(const char *msg, const char *dev_path, struct osd_dev *od, u64 pid) { const struct osd_dev_info *odi = osduld_device_info(od); printk(KERN_NOTICE "exofs: %s %s osd_name-%s pid-0x%llx\n", msg, dev_path ?: "", odi->osdname, _LLU(pid)); }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh57100.00%1100.00%
Total57100.00%1100.00%


static void exofs_free_sbi(struct exofs_sb_info *sbi) { unsigned numdevs = sbi->oc.numdevs; while (numdevs) { unsigned i = --numdevs; struct osd_dev *od = ore_comp_dev(&sbi->oc, i); if (od) { ore_comp_set_dev(&sbi->oc, i, NULL); osduld_put_device(od); } } kfree(sbi->oc.ods); kfree(sbi); }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh8398.81%685.71%
H Hartley Sweeten11.19%114.29%
Total84100.00%7100.00%

/* * This function is called when the vfs is freeing the superblock. We just * need to free our own part. */
static void exofs_put_super(struct super_block *sb) { int num_pend; struct exofs_sb_info *sbi = sb->s_fs_info; /* make sure there are no pending commands */ for (num_pend = atomic_read(&sbi->s_curr_pending); num_pend > 0; num_pend = atomic_read(&sbi->s_curr_pending)) { wait_queue_head_t wq; printk(KERN_NOTICE "%s: !!Pending operations in flight. " "This is a BUG. please report to osd-dev@open-osd.org\n", __func__); init_waitqueue_head(&wq); wait_event_timeout(wq, (atomic_read(&sbi->s_curr_pending) == 0), msecs_to_jiffies(100)); } _exofs_print_device("Unmounting", NULL, ore_comp_dev(&sbi->oc, 0), sbi->one_comp.obj.partition); exofs_sysfs_sb_del(sbi); bdi_destroy(&sbi->bdi); exofs_free_sbi(sbi); sb->s_fs_info = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh12890.78%777.78%
Jens Axboe85.67%111.11%
Sachin Bhamare53.55%111.11%
Total141100.00%9100.00%


static int _read_and_match_data_map(struct exofs_sb_info *sbi, unsigned numdevs, struct exofs_device_table *dt) { int ret; sbi->layout.stripe_unit = le64_to_cpu(dt->dt_data_map.cb_stripe_unit); sbi->layout.group_width = le32_to_cpu(dt->dt_data_map.cb_group_width); sbi->layout.group_depth = le32_to_cpu(dt->dt_data_map.cb_group_depth); sbi->layout.mirrors_p1 = le32_to_cpu(dt->dt_data_map.cb_mirror_cnt) + 1; sbi->layout.raid_algorithm = le32_to_cpu(dt->dt_data_map.cb_raid_algorithm); ret = ore_verify_layout(numdevs, &sbi->layout); EXOFS_DBGMSG("exofs: layout: " "num_comps=%u stripe_unit=0x%x group_width=%u " "group_depth=0x%llx mirrors_p1=%u raid_algorithm=%u\n", numdevs, sbi->layout.stripe_unit, sbi->layout.group_width, _LLU(sbi->layout.group_depth), sbi->layout.mirrors_p1, sbi->layout.raid_algorithm); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh156100.00%6100.00%
Total156100.00%6100.00%


static unsigned __ra_pages(struct ore_layout *layout) { const unsigned _MIN_RA = 32; /* min 128K read-ahead */ unsigned ra_pages = layout->group_width * layout->stripe_unit / PAGE_SIZE; unsigned max_io_pages = exofs_max_io_pages(layout, ~0); ra_pages *= 2; /* two stripes */ if (ra_pages < _MIN_RA) ra_pages = roundup(_MIN_RA, ra_pages / 2); if (ra_pages > max_io_pages) ra_pages = max_io_pages; return ra_pages; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh77100.00%2100.00%
Total77100.00%2100.00%

/* @odi is valid only as long as @fscb_dev is valid */
static int exofs_devs_2_odi(struct exofs_dt_device_info *dt_dev, struct osd_dev_info *odi) { odi->systemid_len = le32_to_cpu(dt_dev->systemid_len); if (likely(odi->systemid_len)) memcpy(odi->systemid, dt_dev->systemid, OSD_SYSTEMID_LEN); odi->osdname_len = le32_to_cpu(dt_dev->osdname_len); odi->osdname = dt_dev->osdname; /* FIXME support long names. Will need a _put function */ if (dt_dev->long_name_offset) return -EINVAL; /* Make sure osdname is printable! * mkexofs should give us space for a null-terminator else the * device-table is invalid. */ if (unlikely(odi->osdname_len >= sizeof(dt_dev->osdname))) odi->osdname_len = sizeof(dt_dev->osdname) - 1; dt_dev->osdname[odi->osdname_len] = 0; /* If it's all zeros something is bad we read past end-of-obj */ return !(odi->systemid_len || odi->osdname_len); }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh12392.48%150.00%
Dan Carpenter107.52%150.00%
Total133100.00%2100.00%


static int __alloc_dev_table(struct exofs_sb_info *sbi, unsigned numdevs, struct exofs_dev **peds) { struct __alloc_ore_devs_and_exofs_devs { /* Twice bigger table: See exofs_init_comps() and comment at * exofs_read_lookup_dev_table() */ struct ore_dev *oreds[numdevs * 2 - 1]; struct exofs_dev eds[numdevs]; } *aoded; struct exofs_dev *eds; unsigned i; aoded = kzalloc(sizeof(*aoded), GFP_KERNEL); if (unlikely(!aoded)) { EXOFS_ERR("ERROR: failed allocating Device array[%d]\n", numdevs); return -ENOMEM; } sbi->oc.ods = aoded->oreds; *peds = eds = aoded->eds; for (i = 0; i < numdevs; ++i) aoded->oreds[i] = &eds[i].ored; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh13798.56%133.33%
Masanari Iida10.72%133.33%
Rashika Kheria10.72%133.33%
Total139100.00%3100.00%


static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi, struct osd_dev *fscb_od, unsigned table_count) { struct ore_comp comp; struct exofs_device_table *dt; struct exofs_dev *eds; unsigned table_bytes = table_count * sizeof(dt->dt_dev_table[0]) + sizeof(*dt); unsigned numdevs, i; int ret; dt = kmalloc(table_bytes, GFP_KERNEL); if (unlikely(!dt)) { EXOFS_ERR("ERROR: allocating %x bytes for device table\n", table_bytes); return -ENOMEM; } sbi->oc.numdevs = 0; comp.obj.partition = sbi->one_comp.obj.partition; comp.obj.id = EXOFS_DEVTABLE_ID; exofs_make_credential(comp.cred, &comp.obj); ret = exofs_read_kern(fscb_od, comp.cred, &comp.obj, 0, dt, table_bytes); if (unlikely(ret)) { EXOFS_ERR("ERROR: reading device table\n"); goto out; } numdevs = le64_to_cpu(dt->dt_num_devices); if (unlikely(!numdevs)) { ret = -EINVAL; goto out; } WARN_ON(table_count != numdevs); ret = _read_and_match_data_map(sbi, numdevs, dt); if (unlikely(ret)) goto out; ret = __alloc_dev_table(sbi, numdevs, &eds); if (unlikely(ret)) goto out; /* exofs round-robins the device table view according to inode * number. We hold a: twice bigger table hence inodes can point * to any device and have a sequential view of the table * starting at this device. See exofs_init_comps() */ memcpy(&sbi->oc.ods[numdevs], &sbi->oc.ods[0], (numdevs - 1) * sizeof(sbi->oc.ods[0])); /* create sysfs subdir under which we put the device table * And cluster layout. A Superblock is identified by the string: * "dev[0].osdname"_"pid" */ exofs_sysfs_sb_add(sbi, &dt->dt_dev_table[0]); for (i = 0; i < numdevs; i++) { struct exofs_fscb fscb; struct osd_dev_info odi; struct osd_dev *od; if (exofs_devs_2_odi(&dt->dt_dev_table[i], &odi)) { EXOFS_ERR("ERROR: Read all-zeros device entry\n"); ret = -EINVAL; goto out; } printk(KERN_NOTICE "Add device[%d]: osd_name-%s\n", i, odi.osdname); /* the exofs id is currently the table index */ eds[i].did = i; /* On all devices the device table is identical. The user can * specify any one of the participating devices on the command * line. We always keep them in device-table order. */ if (fscb_od && osduld_device_same(fscb_od, &odi)) { eds[i].ored.od = fscb_od; ++sbi->oc.numdevs; fscb_od = NULL; exofs_sysfs_odev_add(&eds[i], sbi); continue; } od = osduld_info_lookup(&odi); if (IS_ERR(od)) { ret = PTR_ERR(od); EXOFS_ERR("ERROR: device requested is not found " "osd_name-%s =>%d\n", odi.osdname, ret); goto out; } eds[i].ored.od = od; ++sbi->oc.numdevs; /* Read the fscb of the other devices to make sure the FS * partition is there. */ ret = exofs_read_kern(od, comp.cred, &comp.obj, 0, &fscb, sizeof(fscb)); if (unlikely(ret)) { EXOFS_ERR("ERROR: Malformed participating device " "error reading fscb osd_name-%s\n", odi.osdname); goto out; } exofs_sysfs_odev_add(&eds[i], sbi); /* TODO: verify other information is correct and FS-uuid * matches. Benny what did you say about device table * generation and old devices? */ } out: kfree(dt); if (unlikely(fscb_od && !ret)) { EXOFS_ERR("ERROR: Bad device-table container device not present\n"); osduld_put_device(fscb_od); return -EINVAL; } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Boaz Harrosh55493.90%990.00%
Sachin Bhamare366.10%110.00%
Total590100.00%10100.00%

/* * Read the superblock from the OSD and fill in the fields */
static int exofs_fill_super(struct super_block *sb, void *data, int silent) { struct inode *root; struct exofs_mountopt *opts = data; struct exofs_sb_info *sbi; /*extended info */ struct osd_dev *od; /* Master device */ struct exofs_fscb fscb; /*on-disk superblock info */ struct ore_comp comp; unsigned table_count; int ret; sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); if (!sbi) return -ENOMEM; /* use mount options to fill superblock */ if (opts->is_osdname) { struct osd_dev_info odi = {.systemid_len = 0}; odi.osdname_len = strlen(opts->dev_name); odi.osdname = (u8 *)opts->dev_name; od = osduld_info_lookup(&odi); kfree(opts->dev_name); opts