From a639f12a8385eed5540d9aa6589673ff1b3e5039 Mon Sep 17 00:00:00 2001 From: braam Date: Sun, 24 Mar 2002 23:36:24 +0000 Subject: [PATCH] *** empty log message *** --- lustre/ldlm/ldlm_extent.c | 93 +++++++++++++++++++++++++++++++ lustre/lib/pack_generic.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 lustre/ldlm/ldlm_extent.c create mode 100644 lustre/lib/pack_generic.c diff --git a/lustre/ldlm/ldlm_extent.c b/lustre/ldlm/ldlm_extent.c new file mode 100644 index 0000000..3e1724d --- /dev/null +++ b/lustre/ldlm/ldlm_extent.c @@ -0,0 +1,93 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * Copyright (C) 2002 Cluster File Systems, Inc. + * + * This code is issued under the GNU General Public License. + * See the file COPYING in this distribution + * + * by Cluster File Systems, Inc. + * authors, Peter Braam & + * Phil Schwan + */ + +#define EXPORT_SYMTAB + +#include +#include +#include +#include + +#define DEBUG_SUBSYSTEM S_LDLM + +#include +#include +#include + +/* This function will be called to judge if the granted queue of another child + * (read: another extent) is conflicting and needs its granted queue walked to + * issue callbacks. + * + * This helps to find conflicts between read and write locks on overlapping + * extents. */ +int ldlm_extent_compat(struct ldlm_resource *child, struct ldlm_resource *new) +{ + struct ldlm_extent *child_ex, *new_ex; + + child_ex = ldlm_res2extent(child); + new_ex = ldlm_res2extent(new); + + if (MAX(child_ex->start, new_ex->start) > + MIN(child_ex->end, new_ex->end)) + return 0; + + return 1; +} + +/* The purpose of this function is to return: + * - the maximum extent + * - containing the requested extent + * - and not overlapping existing extents outside the requested one + * + * An alternative policy is to not shrink the new extent when conflicts exist. + * + * To reconstruct our formulas, take a deep breath. */ +int ldlm_extent_policy(struct ldlm_resource *parent, + __u64 *res_id_in, __u64 *res_id_out, + ldlm_mode_t mode, void *data) +{ + struct ldlm_extent *new_ex, *req_ex; + struct list_head *tmp; + + req_ex = (struct ldlm_extent *)res_id_in; + + new_ex = (struct ldlm_extent *)res_id_out; + new_ex->start = 0; + new_ex->end = ~0; + + list_for_each(tmp, &parent->lr_children) { + struct ldlm_resource *res; + struct ldlm_extent *res_ex; + res = list_entry(tmp, struct ldlm_resource, lr_childof); + + res_ex = ldlm_res2extent(res); + + if (res_ex->end < req_ex->start) + new_ex->start = MIN(res_ex->end, new_ex->start); + else { + if (res_ex->start < req_ex->start) + /* Policy: minimize conflict overlap */ + new_ex->start = req_ex->start; + } + if (res_ex->start > req_ex->end) + new_ex->end = MAX(res_ex->start, new_ex->end); + else { + if (res_ex->end > req_ex->end) + /* Policy: minimize conflict overlap */ + new_ex->end = req_ex->end; + } + } + + return 0; +} + diff --git a/lustre/lib/pack_generic.c b/lustre/lib/pack_generic.c new file mode 100644 index 0000000..06a4306 --- /dev/null +++ b/lustre/lib/pack_generic.c @@ -0,0 +1,136 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * Copyright (C) 2001 Cluster File Systems, Inc. + * + * This file is part of Lustre, http://www.lustre.org. + * + * Lustre is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * Lustre 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 Lustre; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * (Un)packing of OST requests + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_SUBSYSTEM S_CLASS + +#include +#include + +int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf) +{ + char *ptr; + struct lustre_msg *m; + int size = 0; + int i; + + for (i=0 ; itype = PTL_RPC_REQUEST; + + m->bufcount = HTON__u32(count); + for (i=0 ; ibuflens[i] = HTON__u32(lens[i]); + } + + ptr = *buf + sizeof(*m) + sizeof(__u32) * count; + for (i=0 ; ibufcount = NTOH__u32(m->bufcount); + + required_len += m->bufcount * sizeof(__u32); + if (len < required_len) { + RETURN(-EINVAL); + } + + for (i=0; ibufcount; i++) { + m->buflens[i] = NTOH__u32(m->buflens[i]); + required_len += size_round(m->buflens[i]); + } + + if (len < required_len) { + RETURN(-EINVAL); + } + + EXIT; + return 0; +} + +void *lustre_msg_buf(int n, struct lustre_msg *m) +{ + int i; + int offset; + + if (n >= m->bufcount || n < 0) { + CERROR("referencing bad sub buffer!\n"); + return NULL; + } + + if (m->buflens[n] == 0) + return NULL; + + offset = sizeof(*m) + m->bufcount * sizeof(__u32); + + for (i=0; i < n; i++ ) + offset += size_round(m->buflens[i]); + + return (char *)m + offset; +} -- 1.8.3.1