struct lu_device *next);
/** @} clio */
+int cl_global_init(void);
+void cl_global_fini(void);
+
#endif /* _LINUX_CL_OBJECT_H */
return dti;
}
+int dt_global_init(void);
+void dt_global_fini(void);
+
#endif /* __LUSTRE_DT_OBJECT_H */
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*
- * lustre/lustre/include/lustre_idmap.h
+ * lustre/lustre/include/lustre_acl.h
*
* MDS data structures.
* See also lustre_idl.h for wire formats of requests.
#define __LUSTRE_LU_OBJECT_H
#include <stdarg.h>
-
-/*
- * struct lu_fid
- */
#include <libcfs/libcfs.h>
-
#include <lustre/lustre_idl.h>
-
#include <lu_ref.h>
struct seq_file;
void (*ldto_stop)(struct lu_device_type *t);
};
+static inline int lu_device_is_md(const struct lu_device *d)
+{
+ return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
+}
+
/**
* Flags for the object layers.
*/
/** @} lu_context */
-struct lu_ucred {
- __u32 uc_valid;
- __u32 uc_o_uid;
- __u32 uc_o_gid;
- __u32 uc_o_fsuid;
- __u32 uc_o_fsgid;
- __u32 uc_uid;
- __u32 uc_gid;
- __u32 uc_fsuid;
- __u32 uc_fsgid;
- __u32 uc_suppgids[2];
- cfs_cap_t uc_cap;
- __u32 uc_umask;
- cfs_group_info_t *uc_ginfo;
- struct md_identity *uc_identity;
-};
-struct lu_ucred *lu_ucred(const struct lu_env *env);
-struct lu_ucred *lu_ucred_check(const struct lu_env *env);
-struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
-
/**
* Output site statistical counters into a buffer. Suitable for
* ll_rd_*()-style functions.
#include <linux/posix_acl_xattr.h>
-#include <lustre_idmap.h>
-#include <md_object.h>
-#include <lu_object.h>
-
typedef struct {
__u16 e_tag;
__u16 e_perm;
#define CFS_ACL_XATTR_COUNT(size, prefix) \
(((size) - sizeof(prefix ## _header)) / sizeof(prefix ## _entry))
+#ifdef HAVE_SERVER_SUPPORT
+struct lu_ucred;
+struct lu_attr;
+struct lustre_idmap_table;
+
extern int lustre_posix_acl_permission(struct lu_ucred *mu, struct lu_attr *la,
int want, posix_acl_xattr_entry *entry,
int count);
extern int lustre_posix_acl_equiv_mode(posix_acl_xattr_entry *entry, mode_t *mode_p,
int count);
-extern ext_acl_xattr_header *
-lustre_posix_acl_xattr_2ext(posix_acl_xattr_header *header, int size);
-extern int
-lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size,
- posix_acl_xattr_header **out);
extern int
lustre_posix_acl_xattr_id2client(struct lu_ucred *mu,
struct lustre_idmap_table *t,
posix_acl_xattr_header *header,
int size, int flags);
-extern void
-lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size);
+
extern int
lustre_ext_acl_xattr_id2server(struct lu_ucred *mu,
struct lustre_idmap_table *t,
ext_acl_xattr_header *header);
+#endif /* HAVE_SERVER_SUPPORT */
+
+extern ext_acl_xattr_header *
+lustre_posix_acl_xattr_2ext(posix_acl_xattr_header *header, int size);
+extern int
+lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size,
+ posix_acl_xattr_header **out);
+extern void
+lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size);
extern void
lustre_ext_acl_xattr_free(ext_acl_xattr_header *header);
extern int
* @{
*/
-#include <md_object.h>
+#include <libcfs/libcfs.h>
#define CFS_NGROUPS_PER_BLOCK ((int)(CFS_PAGE_SIZE / sizeof(gid_t)))
cfs_list_t lit_idmaps[CFS_IDMAP_N_HASHES][CFS_IDMAP_HASHSIZE];
};
+struct lu_ucred;
+
extern void lustre_groups_from_list(cfs_group_info_t *ginfo, gid_t *glist);
extern void lustre_groups_sort(cfs_group_info_t *group_info);
extern int lustre_in_group_p(struct lu_ucred *mu, gid_t grp);
struct lu_client_seq *ss_client_seq;
};
-static inline int lu_device_is_md(const struct lu_device *d)
-{
- return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
-}
-
static inline struct md_device *lu2md_dev(const struct lu_device *d)
{
LASSERT(IS_ERR(d) || lu_device_is_md(d));
struct md_device * md,
struct dt_device * dt);
+int llo_global_init(void);
+void llo_global_fini(void);
+
int lustre_buf2som(void *buf, int rc, struct md_som_data *msd);
int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
void lustre_hsm2buf(void *buf, struct md_hsm *mh);
+struct lu_ucred {
+ __u32 uc_valid;
+ __u32 uc_o_uid;
+ __u32 uc_o_gid;
+ __u32 uc_o_fsuid;
+ __u32 uc_o_fsgid;
+ __u32 uc_uid;
+ __u32 uc_gid;
+ __u32 uc_fsuid;
+ __u32 uc_fsgid;
+ __u32 uc_suppgids[2];
+ cfs_cap_t uc_cap;
+ __u32 uc_umask;
+ cfs_group_info_t *uc_ginfo;
+ struct md_identity *uc_identity;
+};
+
+struct lu_ucred *lu_ucred(const struct lu_env *env);
+
+struct lu_ucred *lu_ucred_check(const struct lu_env *env);
+
+struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
+
+int lu_ucred_global_init(void);
+
+void lu_ucred_global_fini(void);
+
#define md_cap_t(x) (x)
#define MD_CAP_TO_MASK(x) (1 << (x))
#ifndef LLITE_INTERNAL_H
#define LLITE_INTERNAL_H
-
-#include <lustre_acl.h>
-
#include <lustre_debug.h>
#include <lustre_ver.h>
#include <lustre_disk.h> /* for s2sbi */
#ifdef CONFIG_FS_POSIX_ACL
#include <lustre_lite.h>
+#include <lustre_eacl.h>
#include "llite_internal.h"
static inline __u32 rce_hashfunc(uid_t id)
#include <lustre_lite.h>
#include <lustre_dlm.h>
#include <lustre_ver.h>
-#include <lustre_acl.h>
+#include <lustre_eacl.h>
#include "llite_internal.h"
#include <lustre_acl.h>
#include <obd_class.h>
#include <lustre_fid.h>
-#include <md_object.h>
#include <lprocfs_status.h>
#include <lustre_param.h>
#include <lustre_log.h>
/* fid_be_cpu(), fid_cpu_to_be(). */
#include <lustre_fid.h>
#include <obd_lov.h>
-
+#include <lustre_idmap.h>
#include <lustre_param.h>
#include <lustre_mds.h>
#include <lustre/lustre_idl.h>
#include <lustre_ver.h>
#include <lprocfs_status.h>
#include <lustre_mds.h>
-
+#include <lustre_idmap.h>
#include "mdd_internal.h"
#ifdef CONFIG_FS_POSIX_ACL
obdclass-all-objs += cl_object.o cl_page.o cl_lock.o cl_io.o lu_ref.o
obdclass-all-objs += acl.o idmap.o
obdclass-all-objs += md_local_object.o md_attrs.o linkea.o
+obdclass-all-objs += lu_ucred.o
obdclass-objs := $(obdclass-linux-objs) $(obdclass-all-objs)
*/
#define DEBUG_SUBSYSTEM S_SEC
-
+#include <lu_object.h>
#include <lustre_acl.h>
#include <lustre_eacl.h>
#include <obd_support.h>
+#ifdef HAVE_SERVER_SUPPORT
+# include <lustre_idmap.h>
+# include <md_object.h>
+#endif /* HAVE_SERVER_SUPPORT */
#ifdef CONFIG_FS_POSIX_ACL
d->e_id = cpu_to_le32(s->e_id);
}
+#ifdef HAVE_SERVER_SUPPORT
/*
* Check permission based on POSIX ACL.
*/
}
EXPORT_SYMBOL(lustre_posix_acl_create_masq);
+/*
+ * Convert server-side uid/gid in the posix ACL items to the client-side ones.
+ * convert rule:
+ * @CFS_IC_NOTHING
+ * nothing to be converted.
+ * @CFS_IC_ALL
+ * mapped ids are converted to client-side ones,
+ * unmapped ones are converted to "nobody".
+ * @CFS_IC_MAPPED
+ * only mapped ids are converted to "nobody".
+ * @CFS_IC_UNMAPPED
+ * only unmapped ids are converted to "nobody".
+ */
+int lustre_posix_acl_xattr_id2client(struct lu_ucred *mu,
+ struct lustre_idmap_table *t,
+ posix_acl_xattr_header *header,
+ int size, int flags)
+{
+ int count, i;
+ __u32 id;
+ ENTRY;
+
+ if (unlikely(size < 0))
+ RETURN(-EINVAL);
+ else if (!size)
+ RETURN(0);
+
+ if (unlikely(flags == CFS_IC_NOTHING))
+ RETURN(0);
+
+ count = CFS_ACL_XATTR_COUNT(size, posix_acl_xattr);
+ for (i = 0; i < count; i++) {
+ id = le32_to_cpu(header->a_entries[i].e_id);
+ switch (le16_to_cpu(header->a_entries[i].e_tag)) {
+ case ACL_USER_OBJ:
+ case ACL_GROUP_OBJ:
+ case ACL_MASK:
+ case ACL_OTHER:
+ if (id != ACL_UNDEFINED_ID)
+ RETURN(-EIO);
+ break;
+ case ACL_USER:
+ id = lustre_idmap_lookup_uid(mu, t, 1, id);
+ if (flags == CFS_IC_ALL) {
+ if (id == CFS_IDMAP_NOTFOUND)
+ id = NOBODY_UID;
+ header->a_entries[i].e_id = cpu_to_le32(id);
+ } else if (flags == CFS_IC_MAPPED) {
+ if (id != CFS_IDMAP_NOTFOUND)
+ header->a_entries[i].e_id =
+ cpu_to_le32(NOBODY_UID);
+ } else if (flags == CFS_IC_UNMAPPED) {
+ if (id == CFS_IDMAP_NOTFOUND)
+ header->a_entries[i].e_id =
+ cpu_to_le32(NOBODY_UID);
+ }
+ break;
+ case ACL_GROUP:
+ id = lustre_idmap_lookup_gid(mu, t, 1, id);
+ if (flags == CFS_IC_ALL) {
+ if (id == CFS_IDMAP_NOTFOUND)
+ id = NOBODY_GID;
+ header->a_entries[i].e_id = cpu_to_le32(id);
+ } else if (flags == CFS_IC_MAPPED) {
+ if (id != CFS_IDMAP_NOTFOUND)
+ header->a_entries[i].e_id =
+ cpu_to_le32(NOBODY_GID);
+ } else if (flags == CFS_IC_UNMAPPED) {
+ if (id == CFS_IDMAP_NOTFOUND)
+ header->a_entries[i].e_id =
+ cpu_to_le32(NOBODY_GID);
+ }
+ break;
+ default:
+ RETURN(-EIO);
+ }
+ }
+
+ RETURN(0);
+}
+EXPORT_SYMBOL(lustre_posix_acl_xattr_id2client);
+
+/*
+ * Converts client-side uid/gid in the extended ACL items to server-side ones.
+ * convert rule:
+ * mapped ids are converted to server-side ones,
+ * unmapped ones cause "EPERM" error.
+ */
+int lustre_ext_acl_xattr_id2server(struct lu_ucred *mu,
+ struct lustre_idmap_table *t,
+ ext_acl_xattr_header *header)
+{
+ int i, count = le32_to_cpu(header->a_count);
+ __u32 id;
+ ENTRY;
+
+ for (i = 0; i < count; i++) {
+ id = le32_to_cpu(header->a_entries[i].e_id);
+ switch (le16_to_cpu(header->a_entries[i].e_tag)) {
+ case ACL_USER_OBJ:
+ case ACL_GROUP_OBJ:
+ case ACL_MASK:
+ case ACL_OTHER:
+ if (id != ACL_UNDEFINED_ID)
+ RETURN(-EIO);
+ break;
+ case ACL_USER:
+ id = lustre_idmap_lookup_uid(mu, t, 0, id);
+ if (id == CFS_IDMAP_NOTFOUND)
+ RETURN(-EPERM);
+ else
+ header->a_entries[i].e_id = cpu_to_le32(id);
+ break;
+ case ACL_GROUP:
+ id = lustre_idmap_lookup_gid(mu, t, 0, id);
+ if (id == CFS_IDMAP_NOTFOUND)
+ RETURN(-EPERM);
+ else
+ header->a_entries[i].e_id = cpu_to_le32(id);
+ break;
+ default:
+ RETURN(-EIO);
+ }
+ }
+
+ RETURN(0);
+}
+EXPORT_SYMBOL(lustre_ext_acl_xattr_id2server);
+#endif /* HAVE_SERVER_SUPPORT */
+
/* if "new_count == 0", then "new = {a_version, NULL}", NOT NULL. */
static int lustre_posix_acl_xattr_reduce_space(posix_acl_xattr_header **header,
int old_count, int new_count)
EXPORT_SYMBOL(lustre_posix_acl_xattr_filter);
/*
- * Convert server-side uid/gid in the posix ACL items to the client-side ones.
- * convert rule:
- * @CFS_IC_NOTHING
- * nothing to be converted.
- * @CFS_IC_ALL
- * mapped ids are converted to client-side ones,
- * unmapped ones are converted to "nobody".
- * @CFS_IC_MAPPED
- * only mapped ids are converted to "nobody".
- * @CFS_IC_UNMAPPED
- * only unmapped ids are converted to "nobody".
- */
-int lustre_posix_acl_xattr_id2client(struct lu_ucred *mu,
- struct lustre_idmap_table *t,
- posix_acl_xattr_header *header,
- int size, int flags)
-{
- int count, i;
- __u32 id;
- ENTRY;
-
- if (unlikely(size < 0))
- RETURN(-EINVAL);
- else if (!size)
- RETURN(0);
-
- if (unlikely(flags == CFS_IC_NOTHING))
- RETURN(0);
-
- count = CFS_ACL_XATTR_COUNT(size, posix_acl_xattr);
- for (i = 0; i < count; i++) {
- id = le32_to_cpu(header->a_entries[i].e_id);
- switch (le16_to_cpu(header->a_entries[i].e_tag)) {
- case ACL_USER_OBJ:
- case ACL_GROUP_OBJ:
- case ACL_MASK:
- case ACL_OTHER:
- if (id != ACL_UNDEFINED_ID)
- RETURN(-EIO);
- break;
- case ACL_USER:
- id = lustre_idmap_lookup_uid(mu, t, 1, id);
- if (flags == CFS_IC_ALL) {
- if (id == CFS_IDMAP_NOTFOUND)
- id = NOBODY_UID;
- header->a_entries[i].e_id = cpu_to_le32(id);
- } else if (flags == CFS_IC_MAPPED) {
- if (id != CFS_IDMAP_NOTFOUND)
- header->a_entries[i].e_id =
- cpu_to_le32(NOBODY_UID);
- } else if (flags == CFS_IC_UNMAPPED) {
- if (id == CFS_IDMAP_NOTFOUND)
- header->a_entries[i].e_id =
- cpu_to_le32(NOBODY_UID);
- }
- break;
- case ACL_GROUP:
- id = lustre_idmap_lookup_gid(mu, t, 1, id);
- if (flags == CFS_IC_ALL) {
- if (id == CFS_IDMAP_NOTFOUND)
- id = NOBODY_GID;
- header->a_entries[i].e_id = cpu_to_le32(id);
- } else if (flags == CFS_IC_MAPPED) {
- if (id != CFS_IDMAP_NOTFOUND)
- header->a_entries[i].e_id =
- cpu_to_le32(NOBODY_GID);
- } else if (flags == CFS_IC_UNMAPPED) {
- if (id == CFS_IDMAP_NOTFOUND)
- header->a_entries[i].e_id =
- cpu_to_le32(NOBODY_GID);
- }
- break;
- default:
- RETURN(-EIO);
- }
- }
- RETURN(0);
-}
-EXPORT_SYMBOL(lustre_posix_acl_xattr_id2client);
-
-/*
* Release the posix ACL space.
*/
void lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size)
EXPORT_SYMBOL(lustre_posix_acl_xattr_free);
/*
- * Converts client-side uid/gid in the extended ACL items to server-side ones.
- * convert rule:
- * mapped ids are converted to server-side ones,
- * unmapped ones cause "EPERM" error.
- */
-int lustre_ext_acl_xattr_id2server(struct lu_ucred *mu,
- struct lustre_idmap_table *t,
- ext_acl_xattr_header *header)
-
-{
- int i, count = le32_to_cpu(header->a_count);
- __u32 id;
- ENTRY;
-
- for (i = 0; i < count; i++) {
- id = le32_to_cpu(header->a_entries[i].e_id);
- switch (le16_to_cpu(header->a_entries[i].e_tag)) {
- case ACL_USER_OBJ:
- case ACL_GROUP_OBJ:
- case ACL_MASK:
- case ACL_OTHER:
- if (id != ACL_UNDEFINED_ID)
- RETURN(-EIO);
- break;
- case ACL_USER:
- id = lustre_idmap_lookup_uid(mu, t, 0, id);
- if (id == CFS_IDMAP_NOTFOUND)
- RETURN(-EPERM);
- else
- header->a_entries[i].e_id = cpu_to_le32(id);
- break;
- case ACL_GROUP:
- id = lustre_idmap_lookup_gid(mu, t, 0, id);
- if (id == CFS_IDMAP_NOTFOUND)
- RETURN(-EPERM);
- else
- header->a_entries[i].e_id = cpu_to_le32(id);
- break;
- default:
- RETURN(-EIO);
- }
- }
- RETURN(0);
-}
-EXPORT_SYMBOL(lustre_ext_acl_xattr_id2server);
-
-/*
* Release the extended ACL space.
*/
void lustre_ext_acl_xattr_free(ext_acl_xattr_header *header)
#include <lprocfs_status.h>
#include <lustre/lustre_build_version.h>
#include <libcfs/list.h>
+#include <cl_object.h>
+#ifdef HAVE_SERVER_SUPPORT
+# include <dt_object.h>
+# include <md_object.h>
+#endif /* HAVE_SERVER_SUPPORT */
#include "llog_internal.h"
#ifndef __KERNEL__
if (err)
return err;
+ err = cl_global_init();
+ if (err != 0)
+ return err;
+
+#if defined(__KERNEL__) && defined(HAVE_SERVER_SUPPORT)
+ err = dt_global_init();
+ if (err != 0)
+ return err;
+
+ err = lu_ucred_global_init();
+ if (err != 0)
+ return err;
+
+ err = llo_global_init();
+ if (err != 0)
+ return err;
+#endif
+
err = llog_info_init();
if (err)
return err;
}
}
llog_info_fini();
+#ifdef HAVE_SERVER_SUPPORT
+ llo_global_fini();
+ lu_ucred_global_fini();
+ dt_global_fini();
+#endif
+ cl_global_fini();
lu_global_fini();
obd_cleanup_caches();
#define DEBUG_SUBSYSTEM S_SEC
#include <lustre_idmap.h>
+#include <md_object.h>
#include <obd_support.h>
#define lustre_get_group_info(group_info) do { \
#include <lustre_disk.h>
#include <lustre_fid.h>
#include <lu_object.h>
+#include <lu_ref.h>
#include <libcfs/list.h>
static void lu_object_free(const struct lu_env *env, struct lu_object *o);
}
#endif /* __KERNEL__ */
-int cl_global_init(void);
-void cl_global_fini(void);
-int lu_ref_global_init(void);
-void lu_ref_global_fini(void);
-
-int dt_global_init(void);
-void dt_global_fini(void);
-
-int llo_global_init(void);
-void llo_global_fini(void);
-
-/* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
-LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
-
-static struct lu_context_key lu_ucred_key = {
- .lct_tags = LCT_SESSION,
- .lct_init = lu_ucred_key_init,
- .lct_fini = lu_ucred_key_fini
-};
-
-/**
- * Get ucred key if session exists and ucred key is allocated on it.
- * Return NULL otherwise.
- */
-struct lu_ucred *lu_ucred(const struct lu_env *env)
-{
- if (!env->le_ses)
- return NULL;
- return lu_context_key_get(env->le_ses, &lu_ucred_key);
-}
-EXPORT_SYMBOL(lu_ucred);
-
-/**
- * Get ucred key and check if it is properly initialized.
- * Return NULL otherwise.
- */
-struct lu_ucred *lu_ucred_check(const struct lu_env *env)
-{
- struct lu_ucred *uc = lu_ucred(env);
- if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
- return NULL;
- return uc;
-}
-EXPORT_SYMBOL(lu_ucred_check);
-
-/**
- * Get ucred key, which must exist and must be properly initialized.
- * Assert otherwise.
- */
-struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
-{
- struct lu_ucred *uc = lu_ucred_check(env);
- LASSERT(uc != NULL);
- return uc;
-}
-EXPORT_SYMBOL(lu_ucred_assert);
-
/**
* Initialization of global lu_* data.
*/
if (result != 0)
return result;
- LU_CONTEXT_KEY_INIT(&lu_ucred_key);
- result = lu_context_key_register(&lu_ucred_key);
- if (result != 0)
- return result;
-
/*
* At this level, we don't know what tags are needed, so allocate them
* conservatively. This should not be too bad, because this
if (lu_site_shrinker == NULL)
return -ENOMEM;
-#ifdef __KERNEL__
- result = dt_global_init();
- if (result != 0)
- return result;
-
- result = llo_global_init();
- if (result != 0)
- return result;
-#endif
- result = cl_global_init();
-
return result;
}
*/
void lu_global_fini(void)
{
- cl_global_fini();
-#ifdef __KERNEL__
- llo_global_fini();
- dt_global_fini();
-#endif
if (lu_site_shrinker != NULL) {
cfs_remove_shrinker(lu_site_shrinker);
lu_site_shrinker = NULL;
}
- lu_context_key_degister(&lu_global_key);
- lu_context_key_degister(&lu_ucred_key);
+ lu_context_key_degister(&lu_global_key);
/*
* Tear shrinker environment down _after_ de-registering
--- /dev/null
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/obdclass/lu_object.c
+ *
+ * Lustre Object.
+ * These are the only exported functions, they provide some generic
+ * infrastructure for managing object devices
+ *
+ * Author: Nikita Danilov <nikita.danilov@sun.com>
+ */
+
+#define DEBUG_SUBSYSTEM S_CLASS
+
+#include <libcfs/libcfs.h>
+#include <obd_support.h>
+#include <lu_object.h>
+#include <md_object.h>
+
+/* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
+LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
+
+static struct lu_context_key lu_ucred_key = {
+ .lct_tags = LCT_SESSION,
+ .lct_init = lu_ucred_key_init,
+ .lct_fini = lu_ucred_key_fini
+};
+
+/**
+ * Get ucred key if session exists and ucred key is allocated on it.
+ * Return NULL otherwise.
+ */
+struct lu_ucred *lu_ucred(const struct lu_env *env)
+{
+ if (!env->le_ses)
+ return NULL;
+ return lu_context_key_get(env->le_ses, &lu_ucred_key);
+}
+EXPORT_SYMBOL(lu_ucred);
+
+/**
+ * Get ucred key and check if it is properly initialized.
+ * Return NULL otherwise.
+ */
+struct lu_ucred *lu_ucred_check(const struct lu_env *env)
+{
+ struct lu_ucred *uc = lu_ucred(env);
+ if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
+ return NULL;
+ return uc;
+}
+EXPORT_SYMBOL(lu_ucred_check);
+
+/**
+ * Get ucred key, which must exist and must be properly initialized.
+ * Assert otherwise.
+ */
+struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
+{
+ struct lu_ucred *uc = lu_ucred_check(env);
+ LASSERT(uc != NULL);
+ return uc;
+}
+EXPORT_SYMBOL(lu_ucred_assert);
+
+int lu_ucred_global_init(void)
+{
+ LU_CONTEXT_KEY_INIT(&lu_ucred_key);
+ return lu_context_key_register(&lu_ucred_key);
+}
+
+void lu_ucred_global_fini(void)
+{
+ lu_context_key_degister(&lu_ucred_key);
+}