X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdclass%2Fclass_obd.c;h=f0751045284e6382b40edc4b0c5935a870bab172;hb=60b5c3e464d6b4b333506e6db6b0635bb5a06577;hp=e20fd67a6483453356fdf57834bc18686628d18b;hpb=e3a2dd10aa877dfa437a4215d78e6b5d40c87bb4;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index e20fd67..f075104 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -86,6 +86,55 @@ int at_extra = 30; cfs_atomic_t obd_dirty_pages; cfs_atomic_t obd_dirty_transit_pages; +char obd_jobid_var[JOBSTATS_JOBID_VAR_MAX_LEN + 1] = JOBSTATS_DISABLE; +EXPORT_SYMBOL(obd_jobid_var); + +/* Get jobid of current process by reading the environment variable + * stored in between the "env_start" & "env_end" of task struct. + * + * TODO: + * It's better to cache the jobid for later use if there is any + * efficient way, the cl_env code probably could be reused for this + * purpose. + * + * If some job scheduler doesn't store jobid in the "env_start/end", + * then an upcall could be issued here to get the jobid by utilizing + * the userspace tools/api. Then, the jobid must be cached. + */ +int lustre_get_jobid(char *jobid) +{ +#ifdef __KERNEL__ + int jobid_len = JOBSTATS_JOBID_SIZE; +#endif + int ret = 0; + ENTRY; + + memset(jobid, 0, JOBSTATS_JOBID_SIZE); + /* Jobstats isn't enabled */ + if (!memcmp(obd_jobid_var, JOBSTATS_DISABLE, + strlen(JOBSTATS_DISABLE))) { + RETURN(0); + } + + /* Use process name + fsuid as jobid */ + if (!memcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID, + strlen(JOBSTATS_PROCNAME_UID))) { + snprintf(jobid, JOBSTATS_JOBID_SIZE, "%s_%u", + cfs_curproc_comm(), cfs_curproc_fsuid()); + RETURN(0); + } + +#ifdef __KERNEL__ + ret = cfs_get_environ(obd_jobid_var, jobid, &jobid_len); + if (ret) { + CDEBUG((ret != -ENOENT && ret != -EINVAL) ? D_ERROR : D_INFO, + "Get jobid for (%s) failed(%d).\n", obd_jobid_var, ret); + } +#endif + RETURN(ret); +} +EXPORT_SYMBOL(lustre_get_jobid); + static inline void obd_data2conn(struct lustre_handle *conn, struct obd_ioctl_data *data) { @@ -365,7 +414,6 @@ EXPORT_SYMBOL(at_extra); EXPORT_SYMBOL(at_early_margin); EXPORT_SYMBOL(at_history); EXPORT_SYMBOL(ptlrpc_put_connection_superhack); - EXPORT_SYMBOL(proc_lustre_root); /* uuid.c */