Skip to contentSkip to conversation

a revised job patch (with jobfs)

RFC PATCH In review Limin Gu 2 participants 3 messages Dec 16, 2004 – Jan 7, 2005 Documentation

lore
Share & tools
lore

Limin Gu

author
#0 lore raw

RFC PATCH 1/1 a revised job patch (with jobfs)

To Chris Wright:

Quoted 10 lines
Quoted 1 line

+#define FETAL 1 /* being born, not ready for attachments yet */

Heh, odd named state. Could be:
#define INIT 1 /* job initializing, not ready for attachments */

Wait, it's never used...

Lot of this stuff looks like prime header file material.

Quoted 8 lines
Quoted 1 line

+ struct list_head entry; /* List of other jobs - same hash */

These could be hlist_node.

Quoted 1 line

+static struct list_head job_table[HASH_SIZE];

Make this hlist_head.

Above are unchanged for now.

Quoted 33 lines
Quoted 2 lines

+char hidname[16];

static

Review

Quoted 2 lines
(quoted diff) +2 -0
+static char           *hid = NULL;
+MODULE_PARM(hid, "s");

use module_param(hid, charp, 0)

Quoted 1 line

+int jobfs_delete(struct dentry *delete_dentry);

static

Quoted 1 line

+int jobfs_chown(struct dentry *dentry, struct iattr *attr);

static

Quoted 1 line

+int jobfs_nosetattr(struct dentry *dentry, struct iattr *attr);

static

Quoted 1 line

+ .init = NULL,

= NULL initialization is unecessary

Quoted 1 line

+#ifdef DEBUG

I know this is a work in progress (and I think we went over this bit once before). So just a reminder...

Quoted 1 line

+#define DBG_PRINTINIT(s) \

Quoted 8 lines

...there is already pr_debug().

Quoted 1 line

+#define DBG_PRINTEXIT(c) \

...and please don't use macro like this for simple lock (at least for anything final, when locking is debugged ;-) you can always add pr_debugs in the code if needed, and avoid this whole #ifdef DEBUG #else bit.

All those are changed as advised, thanks!

Quoted 4 lines
Quoted 2 lines

+ * job_getjob
+ *

Please use proper kernel-doc style comments.

changed.

Quoted 6 lines
Quoted 6 lines
(quoted diff) +6 -0
+struct job_entry *
+job_getjob(u64 jid)
+{
+   struct list_head *entry = NULL;
+   struct job_entry *tjob = NULL;
+   struct job_entry *job = NULL;
Quoted 8 lines
Quoted 1 line

+

Why not simply lock the table in here? Instead of always locking around this call? If you really need to control lock in some spot add an __job_getjob() w/ no locking and have job_getjob() be like:
lock()
__job_getjob()
unlock()

I see your point, but sometime we need read lock and sometime write lock, and we don't want to immediately unlock it because we want to modify the job table (see job_create). It is just matter of where we code the lock.

Quoted 3 lines
Quoted 1 line

+ if (job->state == ZOMBIE) {

What about == FETAL (or INIT, whatever)?

Yep, it is not used for now.

Quoted 11 lines

Do they need to be created? Can't userspace/lookup handle the dentry creation?

Review

Quoted 6 lines
(quoted diff) +6 -0
+   sprintf(buf, "%d", attached->task->pid);
+   sprintf(attached->jid_buf, "0x%llx", attached->job->jid);
+        attached->pid_dentry = jobfs_create(jobsb, job->jid_dentry, buf,
+           S_IFREG|0444, 0, 0, attached->jid_buf, JOB_FILE_READ);
+   attached->pids_dentry = jobfs_create(jobsb, piddirs, buf,
+           S_IFREG|0444, 0, 0, attached->jid_buf, JOB_FILE_READ);

Mixed tabs and spaces. And, jobfs_create can fail.

job_create gets called when user request to create a job, the dentries are created at that time. Yes, any of the jobfs_create could fail, then userspace operations on that job would suffer, but should job_create fail because jobfs_create fails?

I do add some error checking there.

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+error_return:
+   DBG_PRINTEXIT(errcode);
+   if (attached) kfree(attached);

kfree(NULL) is ok.

changed, thanks!

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+           if (waitcnt > 0) {
+                   wake_up_interruptible(&job->wait);

wake_up_interruptible_all?

unsure about this one, so not changed.

Quoted 12 lines

Review

Quoted 10 lines
(quoted diff) +9 -0
+#if 0      /* XXX - Use if capable is not present */
+   if (current->euid != 0)
+           return -EPERM;
+#else
+   if (!capable(CAP_SYS_RESOURCE)) {
+           errcode = -EPERM;
+           goto error_return;
+   }
+#endif

Make this unconditionally capable()

changed. The code was old.

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+   /* create files in jobfs for the new job */
+   sprintf(buf1, "0x%llx", job->jid);
+   sprintf(attached->jid_buf, "0x%llx", job->jid);

Why is this a buffer, and not just the jid? In fact, what is it used for? Looks superfluous.

buf1 is indeed unnecessary. check out the revised code.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+   job = job_getjob(jid);

This is and odd interface. AFAICT, every caller already knows job, and passes job->jid only to lookup job again from jid.

Good point. I changed to directly pass the job point than jid.

Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+   if (!job)
+           return -ENODATA;
+
+   if (list_empty(&job->attached))
+           return -ESRCH;
+   else {
+           attached = list_entry(job->attached.next, struct job_attach, entry);

Is primary task always at this list location?

Yes, it is the first one in the attached list.

Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+    * Set job_table_sem, so no jobs can be deleted while doing
+    * this operation.
+    */
+   JOB_WLOCK(&job_table_sem);

Why? This doesn't update any jobs or job list does it?

Just don't want job deletion or creation before the hid change is finished.

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+        strcpy(name, dentry->d_name.name);
+        if (sscanf(name, "%llx", &jid) != 1)
+                return -EINVAL;

looks like you don't need tmp buffer, just scan directly from d_name.

Right, thanks!

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+
+   job = job_getjob(jid);

Why no locking on this call to job_getjob()?

my bad, should have the lock.

Quoted 28 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+        if (!job)
+                return -EINVAL;
+
+        if (capable(CAP_SYS_RESOURCE) || (current->uid == job->user)) {
+           job->user = attr->ia_uid;

This is unconditional, regardless of the type of attr change? Why CAP_SYS_RESOURCE?

Review

Quoted 3 lines
(quoted diff) +3 -0
+           if (ia_valid & ATTR_UID) {
+                   inode->i_uid = attr->ia_uid;
+                   if (ia_valid & ATTR_GID)

Why is this nested under ATTR_UID?

Review

Quoted 3 lines
(quoted diff) +3 -0
+                           inode->i_gid = attr->ia_gid;
+                   return 0;
+           }

Perhaps you could filter the ia_valid types you care about, do local changes, then just call at least inode_setattr(), and perhaps also check inode_change_ok() first.

Review

Quoted 2 lines
(quoted diff) +2 -0
+   jobfs_create_files(sb, root);
+        return 0;
Quoted 8 lines

Mixed tabs and spaces. And make sure to check error here and do proper cleanup.

Review

Quoted 3 lines
(quoted diff) +3 -0
+   if (!delete_dentry->d_inode)
+           return 0;
+   down (&delete_dentry->d_inode->i_sem);

This should be the parent i_sem.

Thanks!

Quoted 27 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+static int jobfs_open(struct inode *inode, struct file *filp)
+{
+   filp->private_data = inode->u.generic_ip;

Doesn't seem like this is necessary. It's not per file data, but per inode, so it'll be there in jobfs_read, for example, via filp->f_dentry->d_inode, right?

Review

Quoted 11 lines
(quoted diff) +11 -0
+   return 0;
+}
+
+static ssize_t jobfs_read(struct file *filp, char *buf,
+              size_t count, loff_t *offset)
+{
+   char *hbuf = (char *) filp->private_data;
+   int len;
+   char tmp[JOBFS_BUF];
+
+   len = snprintf(tmp, JOBFS_BUF, hbuf);

A) Is there anyway that hbuf could get printf format characters in it (like %n)? Safer to use a format %s here.

B) Why copy it over to tmp buf?

C) Just use simple_read_from_buffer()

Quoted 10 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+   if (*offset > len)
+           return 0;
+   if (count > len - *offset)
+           count = len - *offset;
+
+   if (copy_to_user(buf, tmp + *offset, count))
+           return -EFAULT;
+   *offset += count;
+   return count;
+}

I stole the open and read codes. The content of those readable files are just numbers, either pid or jid (u64).

I'll try to see if there are better ways to do this.

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+   tmp1 = strchr(tmp, ' ');
+                if (!tmp1)
+                        return -EINVAL;
+                *tmp1 = '\0';
+                tmp1++;

This is looking like an odd interface. Could these things get their own entries?

They share one writable file because these operations are neither frequent nor concurrent. But different entries may be more appropriate.

Quoted 11 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+   if (copy_from_user(tmp, buf, count))
+           return -EFAULT;
+   if (sscanf(tmp, "%u", &h) != 1)

Should h be unsigned int (esp for 64-bit machines where unsigned long is 64-bit)?

Review

Quoted 2 lines
(quoted diff) +2 -0
+   piddirs = jobfs_create(sb, root, "pids", S_IFDIR|0555, 0, 0,
+           data, JOB_RDIR);

jobfs_create can fail, so jobsf_create_files should also be able to fail.

Modified. Thanks!

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+   /* Initialize the list for accounting subscribers */
+   for (i = 0; i < JOB_ACCT_COUNT; i++) {
+           acct_list[i] = NULL;
+   }

This is already initialized to NULL since it's in bss.

removed.

Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +6 -0
+   /* Get hostID string and fill in jid_template hostID segment */
+   if (hid) {
+           jid_hid = (int)simple_strtoul(hid, &hid, 16);
+   } else {
+           jid_hid = 0;
+   }

This seems to make the static initialization to DISABLED unused.

Good catch, jid_hid does not need to be initialized as DISABLED.

Chris, thanks again for your review, I hope the revised version will be better. :)

To Andreas Schwab:

Quoted 3 lines

Calling it "job" whould be quite confusing since it is already used to refer to all processes in a process group in the shell.

Unfortunatly that's the name SGI has been using for quite a long time. Job is the middle layer of PAGG(process aggregates)/job/CSA(comprehensive system accounting) stack.

To Rusty Russell:

Quoted 4 lines
Quoted 1 line

+MODULE_PARM(hid, "s");

Please use module_param from linux/moduleparam.h. MODULE_PARM is obsolescent.

Thanks, this is changed.

To Jan Engelhardt:

Quoted 6 lines
Quoted 2 lines

But adding /proc/<pid>/job needs to patch fs/proc/base.c, we can not do that in a module. Of course if job gets accepted, this won't be a problem.

That depends on whether the community (read: the standard user) needs it. Maybe we could make some procfs functions exported and let jobfs be dependent on procfs (let jobfs using proc_create_dir() for example).

What can I do to make the community needs it? :)

I also replied Robin Holt's and Jeffrey Hundstad's comments that job may belong to /proc in previous email, I would really like to hear more discussions on this.

I have attached the revised version (mostly based on Chris Wright's comments) of job patch, any suggestions are highly appreciated.

Thank you!

--
Limin Gu - Linux System Software
Silicon Graphics Inc., Mountain View, CA

Documentation/job.txt +104 -0
diff -Nur linux.pagg/Documentation/job.txt linux/Documentation/job.txt
@@ -0,0 +1,104 @@
+Linux Jobs - A Process Aggregate (PAGG) Module
+----------------------------------------------
+
+1. Overview
+
+This document provides two additional sections.  Section 2 provides a
+listing of the manual page that describes the particulars of the Linux
+job implementation.  Section 3 provides some information about using 
+the user job library to interface to jobs.
+
+2. Job Man Page
+
+
+JOB(7)		       Linux User's Manual		   JOB(7)
+
+
+NAME
+       job - Linux Jobs kernel module overview
+
+DESCRIPTION
+       A job is a group of related processes all descended from a
+       point of entry process and  identified  by  a  unique  job
+       identifier  (jid).   A  job  can	 contain multiple process
+       groups or sessions, and all processes in one of these sub-
+       groups can only be contained within a single job.
+
+       The  primary  purpose  for  having  jobs is to provide job
+       based resource limits.  The  current  implementation  only
+       provides	 the  job  container  and resource limits will be
+       provided in a later implementation.  When  an  implementa-
+       tion  that provides job limits is available, this descrip-
+       tion will be expanded to provide	 further  explanation  of
+       job based limits.
+
+       Not  every  process  on the system is part of a job.  That
+       is, only processes which are started by a login	initiator
+       like  login, rlogin, rsh and so on, get assigned a job ID.
+       In the Linux environment, jobs are created via a PAM  mod-
+       ule.
+
+       Jobs on Linux are provided using a loadable kernel module.
+       Linux jobs have the following characteristics:
+
+       o   A job is an inescapable container.  A  process  cannot
+	   leave the job nor can a new process be created outside
+	   the job without explicit action,  that  is,	a  system
+	   call with root privilege.
+
+       o   Each	 new  process  inherits	 the jid and limits [when
+	   implemented] from its parent process.
+
+       o   All point of entry processes (job initiators) create a
+	   new	job  and  set  the  job limits [when implemented]
+	   appropriately.
+
+       o   Job initiation on Linux is performed via a PAM session
+	   module.
+
+       o   The job initiator performs authentication and security
+	   checks.
+
+       o   Users can raise and lower their own job limits  within
+	   maximum  values  specified by the system administrator
+	   [when implemented].
+
+       o   Not all processes on a system need be members of a job.
+
+       o   The	process control initialization process (init(1M))
+	   and startup scripts called by init are not part  of	a
+	   job.
+
+
+       Job initiators can be categorized as either interactive or
+       batch processes.	 Limit domain names are	 defined  by  the
+       system  administrator when the user limits database (ULDB)
+       is created.  [The ULDB will be implemented in  conjunction
+       with future job limits work.]
+
+       Note: The existing command jobs(1) applies to shell "jobs"
+       and it is not related to the  Linux  Kernel  Module  jobs.
+       The  at(1),  atd(8),  atq(1), batch(1), atrun(8), atrm(1))
+       man pages refer to  shell  scripts  as  a  job.	 a  shell
+       script.
+
+SEE ALSO
+       job(1), jwait(1), jstat(1), jkill(1)
+
+
+
+
+
+
+
+
+
+3. User Job Library
+
+For developers who wish to make software using Linux Jobs, there exists
+a user job library.  This library contains functions for obtaining information
+about running jobs, creating jobs, detaching, etc.  
+
+The library is part of the job package and can be obtained from oss.sgi.com
+using anonymous ftp.  Look in the /projects/pagg/download directory.  See the
+README in the job source package for more information.
include/linux/job.h +142 -0

142 lines not on this page · raw message

init/Kconfig +25 -0
diff -Nur linux.pagg/init/Kconfig linux/init/Kconfig
@@ -141,6 +141,31 @@
      Linux Jobs module and the Linux Array Sessions module.  If you will not 
      be using such modules, say N.
 
+config PAGG_JOB
+	tristate "  Process aggregate based jobs"
+	depends on PAGG
+	help
+	  The Job feature implements a type of process aggregate,
+	  or grouping.  A job is the collection of all processes that
+	  are descended from a point-of-entry process.  Examples of such
+	  points-of-entry include telnet, rlogin, and console logins.
+	  A job differs from a session and process group since the job
+	  container (or group) is inescapable.  Only root level processes,
+	  or those with the CAP_SYS_RESOURCE capability, can create new jobs
+	  or escape from a job.
+	
+	  A job is identified by a unique job identifier (jid).  Currently,
+	  that jid can be used to obtain status information about the job
+	  and the processes it contians.  The jid can also be used to send
+	  signals to all processes contained in the job.  In addition,
+	  other processes can wait for the completion of a job - the event
+	  where the last process contained in the job has exited.
+	
+	  If you want to compile support for jobs into the kernel, select
+	  this entry using Y.  If you want the support for jobs provided as
+	  a module, select this entry using M.  If you do not want support
+	  for jobs, select N.
+
 config SYSCTL
 	bool "Sysctl support"
 	---help---
kernel/job.c +1717 -0

1,717 lines not on this page · raw message

kernel/Makefile +1 -0
diff -Nur linux.pagg/kernel/Makefile linux/kernel/Makefile
@@ -19,6 +19,7 @@
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_COMPAT) += compat.o
 obj-$(CONFIG_PAGG) += pagg.o
+obj-$(CONFIG_PAGG_JOB) += job.o
 obj-$(CONFIG_IKCONFIG) += configs.o
 obj-$(CONFIG_IKCONFIG_PROC) += configs.o
 obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
#1 lore raw

Hi, Limin Gu

This JOB-fs approach is so ambitious, I think. I tried to apply your JOB-fs patch toward 2.6.9, then I noticed some promlems as follows.

(1) The JOB-fs patch needs include/linux/jobctl.h and include/linux/job_acct.h. But these are contained in linux-2.6.9-job.patch, not JOB-fs patch. Since those patches conflict, we need to extract the jobctl.h and job_acct.h from linux-2.6.9-job.patch.

(2) The return value of mkdir() under the /jids is strange.
The directory of 'jids' has a mkdir() method implemented by jobfs_mkdir(). Since jobfs_mkdir() returns the result of job_create() transparently, my mkdir operations alwaly failed.
----------------
/*
* job_create - create a new job and attache the calling process to it.
* @jid: new job id
* @user: job owner
* @options: not used
*
* return 0 on job is DISABLE, -errno on failure, 1 on success */
----------------
This is the description of job_create(). This returns 1 on success, but VFS layer recognize it as a failure.

I modified this as follows:

kaigai_job.c 2005-01-07 20:16:55.518703400 +0900 renamed from job.c 2005-01-06 20:03:47.000000000 +0900 +1 -1
@@ -1505,5 +1505,5 @@
                return -EINVAL;
        ret = job_create(jid, current->uid, 0);
-       return ret;
+       return (ret==1) ? 0 : ((ret==0) ? -EINVAL : ret); // Dirty?
 }
 

(3) We can not make a JOB by using a /bin/mkdir command.
When I execute '/bin/mkdir' on shell program, new process was fork()'ed and execve()'ed. This process calls mkdir() system-call and it create a JOB which contains only the self process.
Then '/bin/mkdir' exits process, and the JOB created by '/bin/mkdir' contains no process. So, the JOB was destroied soon.
For avoidance the problem, we need to 'create_job' command which calls mkdir() and execve('/bin/bash') in the one process.
Or pagg+job framework need to allow the existance of the empty JOB.

(4) "echo '123' > hid" fails by -EPERM.
When we open the 'hid' with O_TRUNC flag, operation returns -EPERM. setattr() method of 'hid' was called on extention of sys_open().
* sys_open() -> filp_open() -> open_namei() -> may_open() -> do_truncate() (When O_TRUNC was appended)

     -> notify_change()
       -> inode's setattr() (It always returns -EPERM.)

If we can't use 'echo', it's pretty inexpediency.

And, would you have this discussion on PAGG-ML also ?
Because LKML has huge traffic, I have not noticed job-fs for two weeks. orz Thanks.

Signature · 2 lines
Linux Promotion Center, NEC
KaiGai Kohei <[email protected]>
author
#2 lore raw
Quoted 6 lines

Hi, Limin Gu

This JOB-fs approach is so ambitious, I think. I tried to apply your JOB-fs patch toward 2.6.9, then I noticed some promlems as follows.

Hi KaiGai Kohei,

Thank you for your interest in job. I am planning to post a slightly modified version of job patch against 2.6.10 pretty soon, and also the pointer to the job userland library and commands.

Quoted 5 lines

(1) The JOB-fs patch needs include/linux/jobctl.h and include/linux/job_acct.h. But these are contained in linux-2.6.9-job.patch, not JOB-fs patch. Since those patches conflict, we need to extract the jobctl.h and job_acct.h from linux-2.6.9-job.patch.

The jobfs patch I posted last time should not need include/linux/jobctl.h and include/linux/job_acct.h, it only needed include/linux/job.h. I don't know why you had that problem.

Your questions below 2-4 are all related to how to use job in the userland. We provide an extensive job library (libjob.so) for C codes, and serveral job commands for shell enviroment. User should use the library and commands instead of directly use /bin/mkdir and echo, the reason is that we want to maintain the job library and command the same as before and we want jobfs as simple as possible.

Quoted 2 lines

(2) The return value of mkdir() under the /jids is strange.

Yes, the return value is hacked to return the newly created jid.

Quoted 26 lines

The directory of 'jids' has a mkdir() method implemented by jobfs_mkdir(). Since jobfs_mkdir() returns the result of job_create() transparently, my mkdir operations alwaly failed.
----------------
/*
* job_create - create a new job and attache the calling process to it.
* @jid: new job id
* @user: job owner
* @options: not used
*
* return 0 on job is DISABLE, -errno on failure, 1 on success */
----------------
This is the description of job_create(). This returns 1 on success, but VFS layer recognize it as a failure.

I modified this as follows:

kaigai_job.c 2005-01-07 20:16:55.518703400 +0900 renamed from job.c 2005-01-06 20:03:47.000000000 +0900 +1 -1
@@ -1505,5 +1505,5 @@
                 return -EINVAL;
         ret = job_create(jid, current->uid, 0);
-       return ret;
+       return (ret==1) ? 0 : ((ret==0) ? -EINVAL : ret); // Dirty?
  }
 
Quoted 1 line

(3) We can not make a JOB by using a /bin/mkdir command.

We provide job_create() library call for job creation.

We also provide a library pam_job.so that allows job creation through PAM modules. For example, if add "account optional /lib/security/pam_job.so" line to /etc/pam.d/rlogin file, every rlogin will create a new job, and all the processes from that login are contained in the same job, unless somebody with proper permission decide to detach (processes or the job).

Quoted 10 lines

When I execute '/bin/mkdir' on shell program, new process was fork()'ed and execve()'ed. This process calls mkdir() system-call and it create a JOB which contains only the self process.
Then '/bin/mkdir' exits process, and the JOB created by '/bin/mkdir' contains no process. So, the JOB was destroied soon.
For avoidance the problem, we need to 'create_job' command which calls mkdir() and execve('/bin/bash') in the one process.
Or pagg+job framework need to allow the existance of the empty JOB.

(4) "echo '123' > hid" fails by -EPERM.

We have job_sethid() library call, and jsethid command avaible.

Quoted 11 lines

When we open the 'hid' with O_TRUNC flag, operation returns -EPERM. setattr() method of 'hid' was called on extention of sys_open().
* sys_open() -> filp_open() -> open_namei() -> may_open()

    -> do_truncate() (When O_TRUNC was appended)
      -> notify_change()
        -> inode's setattr() (It always returns -EPERM.)

If we can't use 'echo', it's pretty inexpediency.

And, would you have this discussion on PAGG-ML also ?
Because LKML has huge traffic, I have not noticed job-fs for two weeks. orz Thanks.

Good idea. Thanks!

I am planning to post the new job patch(with jobfs implementation) and a new job userland rpm, i.e. the job library and commands that work with jobfs instead of the current ioctl calls, today on oss.sgi.com/projects/pagg. Let me know any problems. I appreciate your time.

--Limin

Quoted 4 lines
Signature · 2 lines
Linux Promotion Center, NEC
KaiGai Kohei <[email protected]>