cregit-Linux how code gets into the kernel

Release 4.11 drivers/md/dm-cache-policy.c

Directory: drivers/md
/*
 * Copyright (C) 2012 Red Hat. All rights reserved.
 *
 * This file is released under the GPL.
 */

#include "dm-cache-policy-internal.h"
#include "dm.h"

#include <linux/module.h>
#include <linux/slab.h>

/*----------------------------------------------------------------*/


#define DM_MSG_PREFIX "cache-policy"

static DEFINE_SPINLOCK(register_lock);
static LIST_HEAD(register_list);


static struct dm_cache_policy_type *__find_policy(const char *name) { struct dm_cache_policy_type *t; list_for_each_entry(t, &register_list, list) if (!strcmp(t->name, name)) return t; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber44100.00%1100.00%
Total44100.00%1100.00%


static struct dm_cache_policy_type *__get_policy_once(const char *name) { struct dm_cache_policy_type *t = __find_policy(name); if (t && !try_module_get(t->owner)) { DMWARN("couldn't get module %s", name); t = ERR_PTR(-EINVAL); } return t; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber55100.00%1100.00%
Total55100.00%1100.00%


static struct dm_cache_policy_type *get_policy_once(const char *name) { struct dm_cache_policy_type *t; spin_lock(&register_lock); t = __get_policy_once(name); spin_unlock(&register_lock); return t; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber40100.00%1100.00%
Total40100.00%1100.00%


static struct dm_cache_policy_type *get_policy(const char *name) { struct dm_cache_policy_type *t; t = get_policy_once(name); if (IS_ERR(t)) return NULL; if (t) return t; request_module("dm-cache-%s", name); t = get_policy_once(name); if (IS_ERR(t)) return NULL; return t; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber69100.00%1100.00%
Total69100.00%1100.00%


static void put_policy(struct dm_cache_policy_type *t) { module_put(t->owner); }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber18100.00%1100.00%
Total18100.00%1100.00%


int dm_cache_policy_register(struct dm_cache_policy_type *type) { int r; /* One size fits all for now */ if (type->hint_size != 0 && type->hint_size != 4) { DMWARN("hint size must be 0 or 4 but %llu supplied.", (unsigned long long) type->hint_size); return -EINVAL; } spin_lock(&register_lock); if (__find_policy(type->name)) { DMWARN("attempt to register policy under duplicate name %s", type->name); r = -EINVAL; } else { list_add(&type->list, &register_list); r = 0; } spin_unlock(&register_lock); return r; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber106100.00%1100.00%
Total106100.00%1100.00%

EXPORT_SYMBOL_GPL(dm_cache_policy_register);
void dm_cache_policy_unregister(struct dm_cache_policy_type *type) { spin_lock(&register_lock); list_del_init(&type->list); spin_unlock(&register_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber30100.00%1100.00%
Total30100.00%1100.00%

EXPORT_SYMBOL_GPL(dm_cache_policy_unregister);
struct dm_cache_policy *dm_cache_policy_create(const char *name, dm_cblock_t cache_size, sector_t origin_size, sector_t cache_block_size) { struct dm_cache_policy *p = NULL; struct dm_cache_policy_type *type; type = get_policy(name); if (!type) { DMWARN("unknown policy type"); return ERR_PTR(-EINVAL); } p = type->create(cache_size, origin_size, cache_block_size); if (!p) { put_policy(type); return ERR_PTR(-ENOMEM); } p->private = type; return p; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber9090.00%150.00%
Mikulas Patocka1010.00%150.00%
Total100100.00%2100.00%

EXPORT_SYMBOL_GPL(dm_cache_policy_create);
void dm_cache_policy_destroy(struct dm_cache_policy *p) { struct dm_cache_policy_type *t = p->private; p->destroy(p); put_policy(t); }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber31100.00%1100.00%
Total31100.00%1100.00%

EXPORT_SYMBOL_GPL(dm_cache_policy_destroy);
const char *dm_cache_policy_get_name(struct dm_cache_policy *p) { struct dm_cache_policy_type *t = p->private; /* if t->real is set then an alias was used (e.g. "default") */ if (t->real) return t->real->name; return t->name; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber2665.00%150.00%
Mike Snitzer1435.00%150.00%
Total40100.00%2100.00%

EXPORT_SYMBOL_GPL(dm_cache_policy_get_name);
const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p) { struct dm_cache_policy_type *t = p->private; return t->version; }

Contributors

PersonTokensPropCommitsCommitProp
Mike Snitzer26100.00%1100.00%
Total26100.00%1100.00%

EXPORT_SYMBOL_GPL(dm_cache_policy_get_version);
size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p) { struct dm_cache_policy_type *t = p->private; return t->hint_size; }

Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber24100.00%1100.00%
Total24100.00%1100.00%

EXPORT_SYMBOL_GPL(dm_cache_policy_get_hint_size); /*----------------------------------------------------------------*/

Overall Contributors

PersonTokensPropCommitsCommitProp
Joe Thornber59491.53%125.00%
Mike Snitzer456.93%250.00%
Mikulas Patocka101.54%125.00%
Total649100.00%4100.00%
Directory: drivers/md
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.