1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author Peter Braam <braam@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * For testing and management it is treated as an obd_device,
23 * although * it does not export a full OBD method table (the
24 * requests are coming * in over the wire, so object target modules
25 * do not have a full * method table.)
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_OSC
35 # include <linux/version.h>
36 # include <linux/module.h>
37 # include <linux/mm.h>
38 # include <linux/highmem.h>
39 # include <linux/ctype.h>
40 # include <linux/init.h>
41 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
42 # include <linux/workqueue.h>
43 # include <linux/smp_lock.h>
45 # include <linux/locks.h>
47 #else /* __KERNEL__ */
48 # include <liblustre.h>
55 # include <linux/lustre_dlm.h>
56 #include <linux/obd_class.h>
57 #include "osc_internal.h"
59 /* this only is used now for deleting orphanes */
60 int osc_create(struct obd_export *exp, struct obdo *oa,
61 void *acl, int acl_size, struct lov_stripe_md **ea,
62 struct obd_trans_info *oti)
64 struct osc_creator *oscc = &exp->exp_obd->u.cli.cl_oscc;
70 LASSERT(oa->o_gr > 0);
71 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
72 LASSERT(acl == NULL && acl_size == 0);
74 if (oa->o_gr == FILTER_GROUP_LLOG || oa->o_gr == FILTER_GROUP_ECHO)
75 RETURN(osc_real_create(exp, oa, ea, oti));
77 /* this is the special case where create removes orphans */
78 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
79 oa->o_flags == OBD_FL_DELORPHAN) {
80 spin_lock(&oscc->oscc_lock);
81 if (oscc->oscc_flags & OSCC_FLAG_SYNC_IN_PROGRESS) {
82 spin_unlock(&oscc->oscc_lock);
85 if (!(oscc->oscc_flags & OSCC_FLAG_RECOVERING)) {
86 spin_unlock(&oscc->oscc_lock);
89 oscc->oscc_flags |= OSCC_FLAG_SYNC_IN_PROGRESS;
90 spin_unlock(&oscc->oscc_lock);
91 CDEBUG(D_HA, "%s; oscc recovery started\n",
92 exp->exp_obd->obd_name);
93 LASSERT(oscc->oscc_flags & OSCC_FLAG_RECOVERING);
95 CDEBUG(D_HA, "%s: deleting to next_id: "LPU64"\n",
96 oscc->oscc_obd->obd_name, oa->o_id);
98 rc = osc_real_create(exp, oa, ea, NULL);
99 if (oscc->oscc_obd == NULL) {
100 CWARN("the obd for oscc %p has been freed\n", oscc);
104 spin_lock(&oscc->oscc_lock);
105 oscc->oscc_flags &= ~OSCC_FLAG_SYNC_IN_PROGRESS;
106 if (rc == 0 || rc == -ENOSPC) {
108 oscc->oscc_flags |= OSCC_FLAG_NOSPC;
109 oscc->oscc_flags &= ~OSCC_FLAG_RECOVERING;
110 CDEBUG(D_HA, "%s: oscc recovery finished: %d\n",
111 oscc->oscc_obd->obd_name, rc);
113 CDEBUG(D_ERROR, "%s: oscc recovery failed: %d\n",
114 oscc->oscc_obd->obd_name, rc);
116 spin_unlock(&oscc->oscc_lock);
124 void oscc_init(struct obd_device *obd)
126 struct osc_creator *oscc;
131 oscc = &obd->u.cli.cl_oscc;
132 memset(oscc, 0, sizeof(*oscc));
134 oscc->oscc_obd = obd;
135 spin_lock_init(&oscc->oscc_lock);
136 oscc->oscc_flags |= OSCC_FLAG_RECOVERING;