Changeset - 9a7f470708e2
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 16 years ago 2010-01-11 15:06:46
ohnobinki@ohnopublishing.net
improve vardir support
cleanup prepare_distrenjob()
fix jobs_in_queue consistency
2 files changed with 54 insertions and 40 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -92,7 +92,7 @@ void update_general_info(struct general_
 
int import_general_info(struct general_info*);
 
int updateJobStatsXML(struct distrenjob *job);
 

	
 
char *job_getserialfilename(struct general_info *, unsigned int jobnum);
 
int job_getserialfilename(char **filename, struct general_info *, unsigned int jobnum, int createdir);
 
int distren_mkdir_recurse(char *fname);
 

	
 
/* ********************** Functions ************************* */
 
@@ -138,7 +138,7 @@ int start_data(struct general_info *gene
 

	
 
  if(stat(general_info->files.geninfo, &buffer) == 0)
 
    {
 
      fprintf(stderr, "Previous state file found, loading:\n");
 
      fprintf(stderr, "Previous state file found; loading ``%s'':\n", general_info->files.geninfo);
 

	
 
      fprintf(stderr, "Parsing XML files and restoring previous state...\n");
 
      if(import_general_info(general_info))
 
@@ -206,7 +206,6 @@ int mortition(struct general_info *genin
 
      */
 
      distrenjob_remove(geninfo, job);
 
      distrenjob_free(&job);
 
      geninfo->jobs_in_queue --;
 
      update_xml_joblist(geninfo);
 
    }
 
  else
 
@@ -252,13 +251,14 @@ int restoreJobState(struct distrenjob *j
 
/**
 
   creates a structure from starting data, then calls another
 
   function to actually add that struct to the queue.
 

	
 
   Passed strings must be free()d by the caller.
 
*/
 
int prepare_distrenjob(struct general_info *geninfo, int type, char *name, char *submitter, char *email, int priority, int start_frame, int end_frame, int width, int height)
 
{
 
  int counter;
 
  int counter2;
 
  int tmp;
 
  char *path_with_num;
 
  char *serialfile;
 

	
 
  struct distrenjob *distrenjob;
 
@@ -270,9 +270,9 @@ int prepare_distrenjob(struct general_in
 
  distrenjob->jobnum = geninfo->highest_jobnum;
 

	
 
  distrenjob->type = 1;
 
  distrenjob->name = name;
 
  distrenjob->submitter = submitter;
 
  distrenjob->email = email;
 
  distrenjob->name = strdup(name);
 
  distrenjob->submitter = strdup(submitter);
 
  distrenjob->email = strdup(email);
 
  distrenjob->priority = priority;
 
  distrenjob->width = width;
 
  distrenjob->height = height;
 
@@ -282,40 +282,39 @@ int prepare_distrenjob(struct general_in
 
  if(!distrenjob->frameset)
 
    {
 
      distrenjob_free(&distrenjob);
 
      fprintf(stderr, "OOM\n");
 
      
 
      return 1;
 
    }
 

	
 
  /** prepares all the frames by setting that status to "unassigned" */
 
  /** initialize frameset */
 
  counter2 = start_frame;
 
  for(counter = 0; counter < distrenjob->total_frames; counter++){
 
    distrenjob->frameset[counter].num = counter2;
 
    distrenjob->frameset[counter].status = FRAMESETSTATUS_UNASSIGNED;
 
  for(counter = 0; counter < distrenjob->total_frames; counter++)
 
    {
 
      distrenjob->frameset[counter].num = counter2;
 
      distrenjob->frameset[counter].status = FRAMESETSTATUS_UNASSIGNED;
 
      
 
      counter2 ++;
 
    }
 

	
 
    counter2++;
 
  }
 

	
 
  _distren_asprintf(&path_with_num, "stor/job%d/out/", distrenjob->jobnum);
 
  distren_mkdir_recurse(path_with_num);
 
  serialfile = job_getserialfilename(geninfo, distrenjob->jobnum);
 

	
 
  free(path_with_num);
 
  job_getserialfilename(&serialfile, geninfo, distrenjob->jobnum, 1);
 

	
 
  /**
 
     add job to queue
 
  */
 
  fprintf(stderr, "\nprepare_distrenjob: attempting distrenjob_serialize()\n");
 
  fprintf(stderr, "prepare_distrenjob(): attempting distrenjob_serialize(%d, \"%s\")\n",
 
	  distrenjob->jobnum, serialfile);
 
  distrenjob_serialize(distrenjob, serialfile);
 
  free(serialfile);
 

	
 
  fprintf(stderr, "\nprepare_distrenjob: attempting distrenjob_enqueue()\n");
 
  fprintf(stderr, "prepare_distrenjob(): attempting distrenjob_enqueue()\n");
 
  distrenjob_enqueue(geninfo, distrenjob);
 

	
 
  geninfo->jobs_in_queue ++;
 
  fprintf(stderr, "\nprepare_distrenjob: attempting update_xml_joblist()\n");
 
  fprintf(stderr, "prepare_distrenjob(): attempting update_xml_joblist()\n");
 
  update_xml_joblist(geninfo);
 
  fprintf(stderr, "\nprepare_distrenjob: attempting update_general_info()\n");
 
  fprintf(stderr, "prepare_distrenjob(): attempting update_general_info()\n");
 
  update_general_info(geninfo);
 
  fprintf(stderr, "\nprepare_distrenjob: attempting updateJobStatsXML()\n");
 
  fprintf(stderr, "prepare_distrenjob(): attempting updateJobStatsXML()\n");
 
  updateJobStatsXML(distrenjob);
 

	
 
  return 0;
 
@@ -323,7 +322,8 @@ int prepare_distrenjob(struct general_in
 

	
 

	
 
/**
 
   distrenjob_enqueue: This function adds the job to the queue based on its priority
 
   Adds the job to the queue based on its priority.
 
   Updates geninfo->jobs_in_queue.
 
*/
 
int distrenjob_enqueue(struct general_info *geninfo, struct distrenjob *job)
 
{
 
@@ -349,8 +349,9 @@ int distrenjob_enqueue(struct general_in
 
	*/
 
	prev_job->next = job;
 
	job->next = current_job;
 
	fprintf(stderr, "adding job before jobname: %s\n", current_job->name);
 
	fprintf(stderr, "added job before jobname: ``%s''\n", current_job->name);
 

	
 
	geninfo->jobs_in_queue ++;
 
	return 0;
 
      }
 

	
 
@@ -361,8 +362,9 @@ int distrenjob_enqueue(struct general_in
 
     if it has reached the end of the list, add job there
 
  */
 
  prev_job->next = job;
 
  fprintf(stderr, "adding job at end of queue\n");
 
  fprintf(stderr, "added job at end of queue\n");
 

	
 
  geninfo->jobs_in_queue ++;
 
  return 0;
 
}
 

	
 
@@ -401,7 +403,7 @@ int change_job_priority(struct general_i
 

	
 
  update_xml_joblist(geninfo);
 
  /** reserialize after changes */
 
  serialname = job_getserialfilename(geninfo, job->jobnum);
 
  job_getserialfilename(&serialname, geninfo, job->jobnum, 0);
 
  distrenjob_serialize(job, serialname);
 
  free(serialname);
 

	
 
@@ -630,7 +632,9 @@ struct distrenjob *distrenjob_get(struct
 

	
 

	
 
/**
 
   Removes a distrenjob from the distrenjob linked list. It does not free the distrenjob, however. You should do that with distrenjob_free() from distrenjob.h
 
   Removes a distrenjob from the distrenjob linked list. It does not free the
 
   distrenjob, however. You should do that with distrenjob_free() from distrenjob.h.
 
   Updates geninfo->jobs_in_queue.
 

	
 
   @arg head pointer to the head of the linkedlist of distrenjobs
 
 */
 
@@ -741,7 +745,10 @@ void update_general_info(struct general_
 
  xmlFreeTextWriter(writer);
 
}
 

	
 
// this reads the information from general_info.xml to the general_info structure
 
/**
 
   Reads general state information from general_info.xml
 
   into the general_info structure.
 
*/
 
int import_general_info(struct general_info *general_info)
 
{
 
  xmlDocPtr doc;
 
@@ -790,7 +797,7 @@ struct distrenjob *createJobFromXML(stru
 
  int counter;
 
  int counter2;
 

	
 
  file_name = job_getserialfilename(geninfo, jobnum);
 
  job_getserialfilename(&file_name, geninfo, jobnum, 0);
 

	
 
  doc = xmlParseFile(file_name);
 
  if(!doc)
 
@@ -1318,19 +1325,23 @@ int main(int argc, char *argv[])
 
/**
 
   constructs the filename for a distrenjob's serialized XML
 
   to be stored/retrieved from/in.
 
   @return pointer to filename allocated using something
 
   @arg filename pointer to filename allocated using something
 
           malloc() and free() compatible. Must be free()ed by the
 
	   caller
 
   @return 0 on success
 
 */
 
char *job_getserialfilename(struct general_info *geninfo, unsigned int jobnum)
 
int job_getserialfilename(char **filename, struct general_info *geninfo, unsigned int jobnum, int createdir)
 
{
 
  char *filename;
 

	
 
  _distren_asprintf(&filename, "%s/stor/job/%d/distrenjob.xml",
 
  _distren_asprintf(filename, "%s/stor/job/%d/distrenjob.xml",
 
		    geninfo->config->datadir,
 
		    jobnum);
 

	
 
  return filename;
 
  if(!*filename)
 
    return 1;
 
  
 
  if(createdir)
 
    return distren_mkdir_recurse(*filename);
 
  
 
  return 0;
 
}
 

	
 
int distren_mkdir_recurse(char *dirname)
src/server/distrenjob.h
Show inline comments
 
@@ -32,7 +32,8 @@ typedef unsigned int jobnum_t;
 
/**
 
   Stores Blender Job Info
 
*/
 
struct distrenjob {
 
struct distrenjob
 
{
 
  struct distrenjob *next; /*< next will be NULL unless if there is another distrenjob */
 
  short int type; /*< 1:Blender, 2:something else */
 
  char *name;
 
@@ -107,6 +108,8 @@ void distrenjob_free(struct distrenjob *
 
   DOES run malloc() for you. It could return nonzero on error,
 
   but there are no errors to have yet (except for nomem). This
 
   sets all char* to NULL.
 

	
 
   You have to initialize your own frameset.
 
 */
 
int distrenjob_new(struct distrenjob **distrenjob);
 

	
0 comments (0 inline, 0 general)