<commit_before>/*
 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
 * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU General Public License v.2.
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/smp_lock.h>

#include "../gfs/lm_interface.h"

struct nolock_lockspace {
	unsigned int nl_lvb_size;
};

struct lm_lockops nolock_ops;

static int nolock_mount(char *table_name, char *host_data,
			lm_callback_t cb, lm_fsdata_t *fsdata,
			unsigned int min_lvb_size, int flags,
			struct lm_lockstruct *lockstruct,
			struct kobject *fskobj)
{
	char *c;
	unsigned int jid;
	struct nolock_lockspace *nl;

	/* If there is a "jid=" in the hostdata, return that jid.
	   Otherwise, return zero. */

	c = strstr(host_data, "jid=");
	if (!c)
		jid = 0;
	else {
		c += 4;
		sscanf(c, "%u", &jid);
	}

	nl = kmalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
	if (!nl)
		return -ENOMEM;

	memset(nl, 0, sizeof(struct nolock_lockspace));
	nl->nl_lvb_size = min_lvb_size;

	lockstruct->ls_jid = jid;
	lockstruct->ls_first = 1;
	lockstruct->ls_lvb_size = min_lvb_size;
	lockstruct->ls_lockspace = (lm_lockspace_t *)nl;
	lockstruct->ls_ops = &nolock_ops;
	lockstruct->ls_flags = LM_LSFLAG_LOCAL;

	return 0;
}

static void nolock_others_may_mount(lm_lockspace_t *lockspace)
{
}

static void nolock_unmount(lm_lockspace_t *lockspace)
{
	struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace;
	kfree(nl);
}

static void nolock_withdraw(lm_lockspace_t *lockspace)
{
}

/**
 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
 * @lockspace: the lockspace the lock lives in
 * @name: the name of the lock
 * @lockp: return the lm_lock_t here
 *
 * Returns: 0 on success, -EXXX on failure
 */

static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name,
			   lm_lock_t **lockp)
{
	*lockp = (lm_lock_t *)lockspace;
	return 0;
}

/**
 * nolock_put_lock - get rid of a lock structure
 * @lock: the lock to throw away
 *
 */

static void nolock_put_lock(lm_lock_t *lock)
{
}

/**
 * nolock_lock - acquire a lock
 * @lock: the lock to manipulate
 * @cur_state: the current state
 * @req_state: the requested state
 * @flags: modifier flags
 *
 * Returns: A bitmap of LM_OUT_*
 */

static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state,
				unsigned int req_state, unsigned int flags)
{
	return req_state | LM_OUT_CACHEABLE;
}

/**
 * nolock_unlock - unlock a lock
 * @lock: the lock to manipulate
 * @cur_state: the current state
 *
 * Returns: 0
 */

static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state)
{
	return 0;
}

static void nolock_cancel(lm_lock_t *lock)
{
}

/**
 * nolock_hold_lvb - hold on to a lock value block
 * @lock: the lock the LVB is associated with
 * @lvbp: return the lm_lvb_t here
 *
 * Returns: 0 on success, -EXXX on failure
 */

static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp)
{
	struct nolock_lockspace *nl = (struct nolock_lockspace *)lock;
	int error = 0;

	*lvbp = kmalloc(nl->nl_lvb_size, GFP_KERNEL);
	if (*lvbp)
		memset(*lvbp, 0, nl->nl_lvb_size);
	else
		error = -ENOMEM;

	return error;
}

/**
 * nolock_unhold_lvb - release a LVB
 * @lock: the lock the LVB is associated with
 * @lvb: the lock value block
 *
 */

static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb)
{
	kfree(lvb);
}

/**
 * nolock_sync_lvb - sync out the value of a lvb
 * @lock: the lock the LVB is associated with
 * @lvb: the lock value block
 *
 */

static void nolock_sync_lvb(lm_lock_t *lock, char *lvb)
{
}

static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name,
			    struct file *file, struct file_lock *fl)
{
	struct file_lock *tmp;

	lock_kernel();
	tmp = posix_test_lock(file, fl);
	fl->fl_type = F_UNLCK;
	if (tmp)
		memcpy(fl, tmp, sizeof(struct file_lock));
	unlock_kernel();

	return 0;
}

static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name,
			struct file *file, int cmd, struct file_lock *fl)
{
	int error;
	lock_kernel();
	error = posix_lock_file_wait(file, fl);
	unlock_kernel();
	return error;
}

static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name,
			  struct file *file, struct file_lock *fl)
{
	int error;
	lock_kernel();<commit_msg>posix_test_lock() args updated for 2.6.17<commit_after>/*
 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
 * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU General Public License v.2.
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/smp_lock.h>

#include "../gfs/lm_interface.h"

struct nolock_lockspace {
	unsigned int nl_lvb_size;
};

struct lm_lockops nolock_ops;

static int nolock_mount(char *table_name, char *host_data,
			lm_callback_t cb, lm_fsdata_t *fsdata,
			unsigned int min_lvb_size, int flags,
			struct lm_lockstruct *lockstruct,
			struct kobject *fskobj)
{
	char *c;
	unsigned int jid;
	struct nolock_lockspace *nl;

	/* If there is a "jid=" in the hostdata, return that jid.
	   Otherwise, return zero. */

	c = strstr(host_data, "jid=");
	if (!c)
		jid = 0;
	else {
		c += 4;
		sscanf(c, "%u", &jid);
	}

	nl = kmalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
	if (!nl)
		return -ENOMEM;

	memset(nl, 0, sizeof(struct nolock_lockspace));
	nl->nl_lvb_size = min_lvb_size;

	lockstruct->ls_jid = jid;
	lockstruct->ls_first = 1;
	lockstruct->ls_lvb_size = min_lvb_size;
	lockstruct->ls_lockspace = (lm_lockspace_t *)nl;
	lockstruct->ls_ops = &nolock_ops;
	lockstruct->ls_flags = LM_LSFLAG_LOCAL;

	return 0;
}

static void nolock_others_may_mount(lm_lockspace_t *lockspace)
{
}

static void nolock_unmount(lm_lockspace_t *lockspace)
{
	struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace;
	kfree(nl);
}

static void nolock_withdraw(lm_lockspace_t *lockspace)
{
}

/**
 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
 * @lockspace: the lockspace the lock lives in
 * @name: the name of the lock
 * @lockp: return the lm_lock_t here
 *
 * Returns: 0 on success, -EXXX on failure
 */

static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name,
			   lm_lock_t **lockp)
{
	*lockp = (lm_lock_t *)lockspace;
	return 0;
}

/**
 * nolock_put_lock - get rid of a lock structure
 * @lock: the lock to throw away
 *
 */

static void nolock_put_lock(lm_lock_t *lock)
{
}

/**
 * nolock_lock - acquire a lock
 * @lock: the lock to manipulate
 * @cur_state: the current state
 * @req_state: the requested state
 * @flags: modifier flags
 *
 * Returns: A bitmap of LM_OUT_*
 */

static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state,
				unsigned int req_state, unsigned int flags)
{
	return req_state | LM_OUT_CACHEABLE;
}

/**
 * nolock_unlock - unlock a lock
 * @lock: the lock to manipulate
 * @cur_state: the current state
 *
 * Returns: 0
 */

static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state)
{
	return 0;
}

static void nolock_cancel(lm_lock_t *lock)
{
}

/**
 * nolock_hold_lvb - hold on to a lock value block
 * @lock: the lock the LVB is associated with
 * @lvbp: return the lm_lvb_t here
 *
 * Returns: 0 on success, -EXXX on failure
 */

static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp)
{
	struct nolock_lockspace *nl = (struct nolock_lockspace *)lock;
	int error = 0;

	*lvbp = kmalloc(nl->nl_lvb_size, GFP_KERNEL);
	if (*lvbp)
		memset(*lvbp, 0, nl->nl_lvb_size);
	else
		error = -ENOMEM;

	return error;
}

/**
 * nolock_unhold_lvb - release a LVB
 * @lock: the lock the LVB is associated with
 * @lvb: the lock value block
 *
 */

static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb)
{
	kfree(lvb);
}

/**
 * nolock_sync_lvb - sync out the value of a lvb
 * @lock: the lock the LVB is associated with
 * @lvb: the lock value block
 *
 */

static void nolock_sync_lvb(lm_lock_t *lock, char *lvb)
{
}

static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name,
			    struct file *file, struct file_lock *fl)
{
	struct file_lock tmp;
	int ret;

	lock_kernel();
	ret = posix_test_lock(file, fl, &tmp);
	fl->fl_type = F_UNLCK;
	if (ret)
		memcpy(fl, &tmp, sizeof(struct file_lock));
	unlock_kernel();

	return 0;
}

static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name,
			struct file *file, int cmd, struct file_lock *fl)
{
	int error;
	lock_kernel();
	error = posix_lock_file_wait(file, fl);
	unlock_kernel();
	return error;
}

static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name,
			  struct file *file, struct file_lock *fl)
{
	int error;
	lock_kernel();
{'fraction_non_alphanumeric': 0.11200087757788504, 'fraction_numerical': 0.007020623080298377, 'mean_word_length': 4.242668200115008, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2461217', 'n_tokens_mistral': 3657, 'n_tokens_neox': 3516, 'n_words': 988}