Exemple #1
0
void matr::mult(const extvec * b, extvec * r) {
#ifdef HAVE_THREADS
	if (sstuff_get_threads() == 1) {
#endif
		size_t J;
		for (J = 0; J < rows(); J++) {
			(*r)(J) = mult_line(J, b->const_begin(), b->const_end());
		}
		call_after_mult();
#ifdef HAVE_THREADS
	} else {
		size_t i;
		size_t rws = rows();
		size_t step = rws/(sstuff_get_threads());
		size_t ost = rws % (sstuff_get_threads());
		size_t J_from = 0;
		size_t J_to = 0;
		for (i = 0; i < sstuff_get_threads(); i++) {
			J_to = J_from + step;
			if (i == 0)
				J_to += ost;

			matr_mult_job & f = matr_mult_jobs[i];
			f.set(this, b, r, J_from, J_to);
			set_job(&f, i);
			J_from = J_to;
		}
		
		do_jobs();
		call_after_mult();

	};
#endif
};
Exemple #2
0
/* 
 * builtin_cmd - If the user has typed a built-in command then execute
 *    it immediately.  
 */
int builtin_cmd(char **argv) 
{
    char *cmd = argv[0];

    if (!strcmp(cmd, "help")) { /* quit command */
      do_help();  
      return 1;
    }

    if (!strcmp(cmd, "stop")) { /* quit command */
      do_stop(argv);
      return 1;
    }

    if (!strcmp(cmd, "exit")) { /* quit command */
      do_exit();
      return 1;
    }

    if (!strcmp(cmd, "jobs")) { /* jobs command */
      do_jobs();
      return 1;    
    }

    if (!strcmp(cmd, "bg")) { /* bg and fg commands */
      do_bg(argv);
      return 1;
    }

    if (!strcmp(cmd, "fg")) { /* bg and fg commands */
      do_fg(argv);
      return 1;
    }

    if (!strcmp(cmd, "kill")) { /* bg and fg commands */
      do_kill(argv);
      return 1;
    }


    return 0;     /* not a builtin command */
}
Exemple #3
0
void matr_rect::mult(const extvec * b, extvec * r) {
	size_t J;
	size_t i, j;
	for (i = 0; i < b->size(); i++)
		(*r)(i) = 0;

#ifdef HAVE_THREADS
	if (sstuff_get_threads() == 1) {
#endif
		for (j = y_from; j <= y_to; j++) {
			for (i = x_from; i <= x_to; i++) {
				J = i + j*n_grid_cols;
				(*r)(J) = mult_line(J, b->const_begin(), b->const_end());
			}
		}
		call_after_mult();

#ifdef HAVE_THREADS
	} else {
		size_t i;
		size_t rws = y_to-y_from+1;
		size_t step = rws/(sstuff_get_threads());
		size_t ost = rws % (sstuff_get_threads());
		size_t J_from = y_from;
		size_t J_to = 0;
		for (i = 0; i < sstuff_get_threads(); i++) {
			J_to = J_from + step;
			if (i == 0)
				J_to += ost;

			matr_rect_mult_job & f = matr_rect_mult_jobs[i];
			f.set(this, b, r, J_from, J_to);
			set_job(&f, i);
			J_from = J_to;
		}
		
		do_jobs();
		call_after_mult();
	}
#endif
};
Exemple #4
0
Fichier : bls.c Projet : AlD/bareos
int main (int argc, char *argv[])
{
   int i, ch;
   FILE *fd;
   char line[1000];
   char *VolumeName = NULL;
   char *bsrName = NULL;
   char *DirectorName = NULL;
   bool ignore_label_errors = false;
   DIRRES *director = NULL;

   setlocale(LC_ALL, "");
   bindtextdomain("bareos", LOCALEDIR);
   textdomain("bareos");
   init_stack_dump();
   lmgr_init_thread();

   working_directory = "/tmp";
   my_name_is(argc, argv, "bls");
   init_msg(NULL, NULL);              /* initialize message handler */

   OSDependentInit();

   ff = init_find_files();

   while ((ch = getopt(argc, argv, "b:c:D:d:e:i:jkLpvV:?")) != -1) {
      switch (ch) {
      case 'b':
         bsrName = optarg;
         break;

      case 'c':                    /* specify config file */
         if (configfile != NULL) {
            free(configfile);
         }
         configfile = bstrdup(optarg);
         break;

      case 'D':                    /* specify director name */
         if (DirectorName != NULL) {
            free(DirectorName);
         }
         DirectorName = bstrdup(optarg);
         break;

      case 'd':                    /* debug level */
         if (*optarg == 't') {
            dbg_timestamp = true;
         } else {
            debug_level = atoi(optarg);
            if (debug_level <= 0) {
               debug_level = 1;
            }
         }
         break;

      case 'e':                    /* exclude list */
         if ((fd = fopen(optarg, "rb")) == NULL) {
            berrno be;
            Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"),
               optarg, be.bstrerror());
            exit(1);
         }
         while (fgets(line, sizeof(line), fd) != NULL) {
            strip_trailing_junk(line);
            Dmsg1(100, "add_exclude %s\n", line);
            add_fname_to_exclude_list(ff, line);
         }
         fclose(fd);
         break;

      case 'i':                    /* include list */
         if ((fd = fopen(optarg, "rb")) == NULL) {
            berrno be;
            Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"),
               optarg, be.bstrerror());
            exit(1);
         }
         while (fgets(line, sizeof(line), fd) != NULL) {
            strip_trailing_junk(line);
            Dmsg1(100, "add_include %s\n", line);
            add_fname_to_include_list(ff, 0, line);
         }
         fclose(fd);
         break;

      case 'j':
         list_jobs = true;
         break;

      case 'k':
         list_blocks = true;
         break;

      case 'L':
         dump_label = true;
         break;

      case 'p':
         ignore_label_errors = true;
         forge_on = true;
         break;

      case 'v':
         verbose++;
         break;

      case 'V':                    /* Volume name */
         VolumeName = optarg;
         break;

      case '?':
      default:
         usage();

      } /* end switch */
   } /* end while */
   argc -= optind;
   argv += optind;

   if (!argc) {
      Pmsg0(0, _("No archive name specified\n"));
      usage();
   }

   if (configfile == NULL) {
      configfile = bstrdup(CONFIG_FILE);
   }

   my_config = new_config_parser();
   parse_sd_config(my_config, configfile, M_ERROR_TERM);

   LockRes();
   me = (STORES *)GetNextRes(R_STORAGE, NULL);
   if (!me) {
      UnlockRes();
      Emsg1(M_ERROR_TERM, 0, _("No Storage resource defined in %s. Cannot continue.\n"),
            configfile);
   }
   UnlockRes();

  if (DirectorName) {
      foreach_res(director, R_DIRECTOR) {
         if (bstrcmp(director->hdr.name, DirectorName)) {
            break;
         }
      }
      if (!director) {
         Emsg2(M_ERROR_TERM, 0, _("No Director resource named %s defined in %s. Cannot continue.\n"),
               DirectorName, configfile);
      }
   }

   load_sd_plugins(me->plugin_directory, me->plugin_names);

   read_crypto_cache(me->working_directory, "bareos-sd",
                     get_first_port_host_order(me->SDaddrs));

   if (ff->included_files_list == NULL) {
      add_fname_to_include_list(ff, 0, "/");
   }

   for (i=0; i < argc; i++) {
      if (bsrName) {
         bsr = parse_bsr(NULL, bsrName);
      }
      jcr = setup_jcr("bls", argv[i], bsr, director, VolumeName, 1); /* acquire for read */
      if (!jcr) {
         exit(1);
      }
      jcr->ignore_label_errors = ignore_label_errors;
      dev = jcr->dcr->dev;
      if (!dev) {
         exit(1);
      }
      dcr = jcr->dcr;
      rec = new_record();
      attr = new_attr(jcr);
      /*
       * Assume that we have already read the volume label.
       * If on second or subsequent volume, adjust buffer pointer
       */
      if (dev->VolHdr.PrevVolumeName[0] != 0) { /* second volume */
         Pmsg1(0, _("\n"
                    "Warning, this Volume is a continuation of Volume %s\n"),
                dev->VolHdr.PrevVolumeName);
      }

      if (list_blocks) {
         do_blocks(argv[i]);
      } else if (list_jobs) {
         do_jobs(argv[i]);
      } else {
         do_ls(argv[i]);
      }
      do_close(jcr);
   }
   if (bsr) {
      free_bsr(bsr);
   }
   term_include_exclude_files(ff);
   term_find_files(ff);
   return 0;
}
Exemple #5
0
int capfs_ftruncate64(int fd, int64_t length)
{
	int i;
	ireq req;

	memset(&req, 0, sizeof(req));
	/* check for badness */
	if (fd < 0 || fd >= CAPFS_NR_OPEN 
		 || (pfds[fd] && pfds[fd]->fs == FS_RESV)) 
	{
		errno = EBADF;
		return(-1);
	}  

	/* check for UNIX */
	if (!pfds[fd] || pfds[fd]->fs==FS_UNIX) {
#ifndef LARGE_FILE_SUPPORT
		if ((off_t) length == length) {
			return ftruncate(fd, (off_t) length);
		}
		else {
			errno = EINVAL;
			return(-1);
		}
#else
		return ftruncate64(fd, length);
#endif
	}

	if (pfds[fd]->fs == FS_PDIR) {
		errno = EISDIR;
		return(-1);
	}
	if (capfs_mode == 0)
	{
		req.majik_nr             = IOD_MAJIK_NR;
		req.release_nr           = CAPFS_RELEASE_NR;
		req.type                 = IOD_FTRUNCATE;
		req.dsize                = 0;
		req.req.ftruncate.f_ino  = FINO;
		req.req.ftruncate.cap    = pfds[fd]->fd.cap;
		req.req.ftruncate.length = length;

		/* build job to send reqs and recv acks */
		if (build_simple_jobs(pfds[fd], &req) < 0) {
			LOG(stderr, WARNING_MSG, SUBSYS_LIB,  "capfs_ftruncate: build_simple_jobs failed\n");
			return(-1);
		}

		/* call do_job */
		while (!jlist_empty(active_p)) {
			if (do_jobs(active_p, &socks, -1) < 0) {
				LOG(stderr, WARNING_MSG, SUBSYS_LIB,  "capfs_ftruncate: do_jobs failed\n");
				return(-1);
			}
		}

		/* check acks from iods */
		for (i=0; i < PCNT; i++) {
			if (pfds[fd]->fd.iod[i].ack.status) {
				LOG(stderr, WARNING_MSG, SUBSYS_LIB,  "capfs_ftruncate: non-zero status returned from iod %d\n", i);
				errno = pfds[fd]->fd.iod[i].ack.eno;
				return(-1);
			}
		}
	}
	return(0);
}
Exemple #6
0
int capfs_read(int fd, char *buf, size_t count)
{
	int i;
	int64_t size = 0;
	fdesc_p pfd_p = pfds[fd];

	/* variables added for correct handling of EOF */
	char *contacted;
	int64_t exp_next_off, act_last_off, known_file_sz, calc_file_sz, start_off;

	if (fd < 0 || fd >= CAPFS_NR_OPEN 
	    || (pfds[fd] && pfds[fd]->fs == FS_RESV)) {
		errno = EBADF;
		return(-1);
	} 
	if (capfs_mode == 1) {
		LOG(stderr, CRITICAL_MSG, SUBSYS_LIB, "capfs_read is not yet implemented for capfs! Please use"
				"the VFS interface for accessing such files\n");
		errno = ENOSYS;
		return -1;
	}

	if (!pfd_p || pfd_p->fs == FS_UNIX) return(unix_read(fd, buf, count));
	if (pfd_p->fs == FS_PDIR) return(unix_read(fd, buf, count));

#ifdef STRICT_FDESC_CHECK
	if (do_fdesc_check(fd) < 0) {
		LOG(stderr, CRITICAL_MSG, SUBSYS_LIB,  "check failed at start of capfs_read()\n");
	}
#endif
	start_off = pfd_p->fd.off;
	exp_next_off = pfd_p->fd.off + count;
	known_file_sz = 0;
	contacted = malloc(PCOUNT * sizeof(char));

	for (i = 0; i < PCOUNT; i++) {
		contacted[i] = 0;
		pfd_p->fd.iod[i].ack.status = 0;
		pfd_p->fd.iod[i].ack.dsize  = 0;
	}	

	/* build jobs, including requests and acks */
	if (build_rw_jobs(pfd_p, buf, count, J_READ) < 0) {
		LOG(stderr, WARNING_MSG, SUBSYS_LIB,  "build_rw_jobs failed in capfs_read\n");
		return(-1);
	}

	/* determine what iods we will contact */
	for (i = 0; i < PCOUNT; i++) {
		/* this isn't so efficient, but i don't want to muck with jlist imp. */
		if (j_search(active_p, pfd_p->fd.iod[i].sock) != NULL) {
			contacted[i] = 1;
		}
	}
	
	/* send requests; receive data and acks */
	while (!jlist_empty(active_p)) {
		if (do_jobs(active_p, &socks, -1) < 0) {
			PERROR(SUBSYS_LIB,"do_jobs");
			free(contacted);
			return(-1);
		}
	}

	/* pass through responses, checking for errors, sizes */
	for (i = 0; i < PCOUNT; i++) {
		if (contacted[i]) {
			if (pfd_p->fd.iod[i].ack.status) {
				errno = pfd_p->fd.iod[i].ack.eno;
				free(contacted);
				return -1;
			}

			/* update known file size */
			calc_file_sz = fsize_to_file_size(pfd_p->fd.iod[i].ack.ack.rw.fsize, 
														 i, pfd_p); 
			size += pfd_p->fd.iod[i].ack.dsize;

			if (calc_file_sz > known_file_sz) {
				known_file_sz = calc_file_sz;
			}

		}
	}

	/* check for short read */
	if (exp_next_off <= known_file_sz) {
		/* we definitely did not hit EOF */
		if (size < count) {
			LOG(stderr, WARNING_MSG, SUBSYS_LIB,  " capfs_read: hit hole, read %Ld of %d (everything should be ok)\n",
				 size, count);
		}
		pfd_p->fd.off = exp_next_off;
		size = count; /* ensure correct return value (size might have hole) */
		errno = 0;
	}
	else {
		mack ack;
		mreq req;
		struct sockaddr saddr;
		struct capfs_options opt;
		
		opt.tcp = MGR_USE_TCP;
		opt.use_hcache = 0;

		/* we know we got a short read.  it MIGHT be EOF, or it might just
		 * be that we hit a hole that happened to extend to the end of our
		 * region to read.  we need to figure out which one happened.
		 */
		act_last_off = known_file_sz;

		/* the quick and dirty way to figure out what happened is to
		 * stat() the file.  a better solution would be to collect the
		 * remaining sizes from the iods we didn't already talk to.
		 */

		req.uid = getuid();
		req.gid = getgid();
		req.type = MGR_FSTAT;
		req.dsize = 0;
		req.req.fstat.meta = pfd_p->fd.meta;
		saddr = pfd_p->fd.meta.mgr;

		if (send_mreq_saddr(&opt, &saddr, &req, NULL, &ack, NULL) < 0 || ack.status != 0) {
			PERROR(SUBSYS_LIB,"capfs_read: send_mreq_saddr - ");
			/* error talking to mgr, but not really critical.
			 * assume we hit EOF, return what we know.
			 */
			pfd_p->fd.off = act_last_off;
			size = act_last_off - start_off;
		}
		else {
			/* got a response; determine if we hit EOF */
			if (ack.ack.fstat.meta.u_stat.st_size > known_file_sz) {
				/* the file is in fact bigger than we were told by the
				 * other iods
				 */
				known_file_sz = ack.ack.fstat.meta.u_stat.st_size;
			}
			if (exp_next_off <= known_file_sz) {
				/* didn't really hit EOF */
				if (size < count) {
					LOG(stderr, WARNING_MSG, SUBSYS_LIB,  " capfs_read: hit hole, read %Ld of %d (everything should be ok)\n",
				  		size, count);
				}
				pfd_p->fd.off = exp_next_off;
				size = count; /* ensure correct return value */
				errno = 0;
			}
			else {
				/* we really did hit EOF; return short read */
				if(known_file_sz > start_off)
				{
					pfd_p->fd.off = known_file_sz;
					size = known_file_sz - start_off;
					errno = 0;
				}
				else
				{
					/* apparently tried to read after seeking beyond EOF;
					 * keep current offset but do not return any data
					 */
					pfd_p->fd.off = start_off;
					size = 0;
					errno = 0;
				}
			}
		}
	}

	pfd_p->fd.meta.u_stat.atime = time(NULL);
	LOG(stderr, DEBUG_MSG, SUBSYS_LIB,  "capfs_read: completed %Ld bytes; new offset = %Ld\n", size,
		pfd_p->fd.off);

#ifdef STRICT_FDESC_CHECK
	if (do_fdesc_check(fd) < 0) {
		LOG(stderr, CRITICAL_MSG, SUBSYS_LIB,  "check failed at end of capfs_read()\n");
	}
#endif

	free(contacted);
	return(size);
}