Whamcloud - gitweb
aed40e5a5186f4ddb819cadf3ff4be9551946ec9
[fs/lustre-release.git] / lustre / lclient / lcommon_misc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * cl code shared between vvp and liblustre (and other Lustre clients in the
37  * future).
38  *
39  */
40 #include <obd_class.h>
41 #include <obd_support.h>
42 #include <obd.h>
43
44 #include <lustre_lite.h>
45
46
47 /* Initialize the default and maximum LOV EA and cookie sizes.  This allows
48  * us to make MDS RPCs with large enough reply buffers to hold the
49  * maximum-sized (= maximum striped) EA and cookie without having to
50  * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
51 int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp)
52 {
53         struct lov_stripe_md lsm = { .lsm_magic = LOV_MAGIC_V3 };
54         __u32 valsize = sizeof(struct lov_desc);
55         int rc, easize, def_easize, cookiesize;
56         struct lov_desc desc;
57         __u32 stripes;
58         ENTRY;
59
60         rc = obd_get_info(dt_exp, sizeof(KEY_LOVDESC), KEY_LOVDESC,
61                           &valsize, &desc, NULL);
62         if (rc)
63                 RETURN(rc);
64
65         stripes = min(desc.ld_tgt_count, (__u32)LOV_MAX_STRIPE_COUNT);
66         lsm.lsm_stripe_count = stripes;
67         easize = obd_size_diskmd(dt_exp, &lsm);
68
69         lsm.lsm_stripe_count = desc.ld_default_stripe_count;
70         def_easize = obd_size_diskmd(dt_exp, &lsm);
71
72         cookiesize = stripes * sizeof(struct llog_cookie);
73
74         CDEBUG(D_HA, "updating max_mdsize/max_cookiesize: %d/%d\n",
75                easize, cookiesize);
76
77         rc = md_init_ea_size(md_exp, easize, def_easize, cookiesize);
78         RETURN(rc);
79 }
80
81 /**
82  * This function is used as an upcall-callback hooked by liblustre and llite
83  * clients into obd_notify() listeners chain to handle notifications about
84  * change of import connect_flags. See llu_fsswop_mount() and
85  * lustre_common_fill_super().
86  */
87 int cl_ocd_update(struct obd_device *host,
88                   struct obd_device *watched,
89                   enum obd_notify_event ev, void *owner)
90 {
91         struct lustre_client_ocd *lco;
92         struct client_obd        *cli;
93         __u64 flags;
94         int   result;
95
96         ENTRY;
97         if (!strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
98                 cli = &watched->u.cli;
99                 lco = owner;
100                 flags = cli->cl_import->imp_connect_data.ocd_connect_flags;
101                 CDEBUG(D_SUPER, "Changing connect_flags: "LPX64" -> "LPX64"\n",
102                        lco->lco_flags, flags);
103                 spin_lock(&lco->lco_lock);
104                 lco->lco_flags &= flags;
105                 /* for each osc event update ea size */
106                 if (lco->lco_dt_exp)
107                         cl_init_ea_size(lco->lco_md_exp, lco->lco_dt_exp);
108
109                 spin_unlock(&lco->lco_lock);
110                 result = 0;
111         } else {
112                 CERROR("unexpected notification from %s %s!\n",
113                        watched->obd_type->typ_name,
114                        watched->obd_name);
115                 result = -EINVAL;
116         }
117         RETURN(result);
118 }