+void lustre_msg_set_uid_gid(struct lustre_msg *msg, __u32 *uid, __u32 *gid)
+{
+ switch (msg->lm_magic) {
+ case LUSTRE_MSG_MAGIC_V2: {
+ __u32 opc = lustre_msg_get_opc(msg);
+ struct ptlrpc_body *pb;
+
+ /* Don't set uid/gid for ldlm ast RPCs */
+ if (!opc || opc == LDLM_BL_CALLBACK ||
+ opc == LDLM_CP_CALLBACK || opc == LDLM_GL_CALLBACK)
+ return;
+
+ pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
+ sizeof(struct ptlrpc_body));
+ LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
+
+ if (uid && gid) {
+ pb->pb_uid = *uid;
+ pb->pb_gid = *gid;
+ pb->pb_flags |= MSG_PACK_UID_GID;
+ } else if (!(pb->pb_flags & MSG_PACK_UID_GID)) {
+ pb->pb_uid = from_kuid(&init_user_ns, current_uid());
+ pb->pb_gid = from_kgid(&init_user_ns, current_gid());
+ pb->pb_flags |= MSG_PACK_UID_GID;
+ }
+
+ return;
+ }
+ default:
+ LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
+ }
+}
+EXPORT_SYMBOL(lustre_msg_set_uid_gid);
+