+
+static inline void
+ll_inode2id(struct lustre_id *id, struct inode *inode)
+{
+ struct lustre_id *lid = &ll_i2info(inode)->lli_id;
+
+ mdc_pack_id(id, inode->i_ino, inode->i_generation,
+ (inode->i_mode & S_IFMT), id_group(lid),
+ id_fid(lid));
+}
+
+static inline void
+ll_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
+ struct inode *i2, const char *name, int namelen,
+ int mode)
+{
+ LASSERT(i1);
+ ll_inode2id(&data->id1, i1);
+
+ /* it could be directory with mea */
+ data->mea1 = ll_i2info(i1)->lli_mea;
+
+ if (i2) {
+ ll_inode2id(&data->id2, i2);
+ data->mea2 = ll_i2info(i2)->lli_mea;
+ }
+
+ data->valid = 0;
+ data->name = name;
+ data->namelen = namelen;
+ data->create_mode = mode;
+ data->mod_time = LTIME_S(CURRENT_TIME);
+}
+
+struct crypto_helper_ops {
+ int (*init_it_key)(struct inode *inode, struct lookup_intent *it);
+ int (*create_key)(struct inode *dir, mode_t mode, void **key,
+ int* key_size);
+ int (*get_mac)(struct inode *inode, struct iattr *iattr, void*value,
+ int size, void **key, int* key_size);
+ int (*decrypt_key)(struct inode *inode, struct lookup_intent *it);
+ int (*init_inode_key)(struct inode *inode, void *md_key);
+ int (*destroy_key)(struct inode *inode);
+};
+
+/*llite crypto ops for crypto api*/
+struct ll_crypto_info {
+ struct obd_export *ll_gt_exp;
+ struct list_head ll_cops_list;
+ struct crypto_helper_ops *ll_cops;
+ int ll_c_flags;
+};
+#define ll_page2key(page) ((ll_i2info(page->mapping->host))->lli_key_info)
+static inline struct ll_crypto_info* ll_s2crpi(struct super_block *sb)
+{
+ return (struct ll_crypto_info*)ll_s2sbi(sb)->ll_crypto_info;
+}
+static inline struct ll_crypto_info* ll_i2crpi(struct inode *inode)
+{
+ return (struct ll_crypto_info*)ll_i2sbi(inode)->ll_crypto_info;
+}
+
+static inline struct crypto_helper_ops* ll_i2crpops(struct inode *inode)
+{
+ return ll_i2crpi(inode)->ll_cops;
+}
+
+static inline struct crypto_helper_ops* ll_s2crpops(struct super_block *sb)
+{
+ return ll_s2crpi(sb)->ll_cops;
+}
+
+static inline struct obd_export *ll_s2gsexp(struct super_block *sb)
+{
+ struct ll_crypto_info *llci = ll_s2crpi(sb);
+ if (llci)
+ return llci->ll_gt_exp;
+ return NULL;
+}
+static inline struct obd_export *ll_i2gsexp(struct inode *inode)
+{
+ return ll_s2gsexp(inode->i_sb);
+}
+
+static inline
+int ll_crypto_init_it_key(struct inode *inode, struct lookup_intent *it)
+{
+ struct ll_crypto_info *lci = ll_i2crpi(inode);
+ if (lci) {
+ struct crypto_helper_ops *ops = lci->ll_cops;;
+ if (ops && ops->init_it_key)
+ return ops->init_it_key(inode, it);
+ }
+ return 0;
+}
+
+static inline
+int ll_crypto_create_key(struct inode *inode, mode_t mode, void **key,
+ int* key_size)
+{
+ struct ll_crypto_info *lci = ll_i2crpi(inode);
+ if (lci) {
+ struct crypto_helper_ops *ops = lci->ll_cops;;
+ if (ops && ops->create_key)
+ return ops->create_key(inode, mode, key, key_size);
+ }
+ return 0;
+}
+
+static inline
+int ll_crypto_get_mac(struct inode *inode, struct iattr *attr, void *acl,
+ int acl_size, void **mac, int *mac_size)
+{
+ struct ll_crypto_info *lci = ll_i2crpi(inode);
+ if (lci) {
+ struct crypto_helper_ops *ops = lci->ll_cops;
+ if (ops && ops->get_mac)
+ return ops->get_mac(inode, attr, acl, acl_size,
+ mac, mac_size);
+ }
+ return 0;
+}
+
+static inline
+int ll_crypto_decrypt_key(struct inode *inode, struct lookup_intent *it)
+{
+ struct ll_crypto_info *lci = ll_i2crpi(inode);
+ if (lci) {
+ struct crypto_helper_ops *ops = lci->ll_cops;
+ if (ops && ops->decrypt_key)
+ return ops->decrypt_key(inode, it);
+ }
+ return 0;
+}
+
+static inline
+int ll_crypto_init_inode_key(struct inode *inode, void *md_key)
+{
+ struct ll_crypto_info *lci = ll_i2crpi(inode);
+ if (lci) {
+ struct crypto_helper_ops *ops = lci->ll_cops;
+ if (ops && ops->init_inode_key)
+ return ops->init_inode_key(inode, md_key);
+ }
+ return 0;
+}
+
+static inline
+int ll_crypto_destroy_inode_key(struct inode *inode)
+{
+ struct ll_crypto_info *lci = ll_i2crpi(inode);
+ if (lci) {
+ struct crypto_helper_ops *ops = lci->ll_cops;
+ if (ops && ops->destroy_key)
+ return ops->destroy_key(inode);
+ }
+ return 0;
+}
+
+int lustre_init_crypto(struct super_block *sb, char *gkc,
+ struct obd_connect_data *data, int async);
+int lustre_destroy_crypto(struct super_block *sb);
+int ll_set_sb_gksinfo(struct super_block *sb, char *type);
+/* pass this flag to ll_md_real_close() to send close rpc right away */
+#define FMODE_SYNC 00000010