Example #1
0
static int show_modified(struct rev_info *revs,
			 const struct cache_entry *old_entry,
			 const struct cache_entry *new_entry,
			 int report_missing,
			 int cached, int match_missing)
{
	unsigned int mode, oldmode;
	const struct object_id *oid;
	unsigned dirty_submodule = 0;

	if (get_stat_data(new_entry, &oid, &mode, cached, match_missing,
			  &dirty_submodule, &revs->diffopt) < 0) {
		if (report_missing)
			diff_index_show_file(revs, "-", old_entry,
					     &old_entry->oid, 1, old_entry->ce_mode,
					     0);
		return -1;
	}

	if (revs->combine_merges && !cached &&
	    (!oideq(oid, &old_entry->oid) || !oideq(&old_entry->oid, &new_entry->oid))) {
		struct combine_diff_path *p;
		int pathlen = ce_namelen(new_entry);

		p = xmalloc(combine_diff_path_size(2, pathlen));
		p->path = (char *) &p->parent[2];
		p->next = NULL;
		memcpy(p->path, new_entry->name, pathlen);
		p->path[pathlen] = 0;
		p->mode = mode;
		oidclr(&p->oid);
		memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
		p->parent[0].status = DIFF_STATUS_MODIFIED;
		p->parent[0].mode = new_entry->ce_mode;
		oidcpy(&p->parent[0].oid, &new_entry->oid);
		p->parent[1].status = DIFF_STATUS_MODIFIED;
		p->parent[1].mode = old_entry->ce_mode;
		oidcpy(&p->parent[1].oid, &old_entry->oid);
		show_combined_diff(p, 2, revs->dense_combined_merges, revs);
		free(p);
		return 0;
	}

	oldmode = old_entry->ce_mode;
	if (mode == oldmode && oideq(oid, &old_entry->oid) && !dirty_submodule &&
	    !revs->diffopt.flags.find_copies_harder)
		return 0;

	diff_change(&revs->diffopt, oldmode, mode,
		    &old_entry->oid, oid, 1, !is_null_oid(oid),
		    old_entry->name, 0, dirty_submodule);
	return 0;
}
Example #2
0
static void show_new_file(struct rev_info *revs,
			  const struct cache_entry *new_file,
			  int cached, int match_missing)
{
	const struct object_id *oid;
	unsigned int mode;
	unsigned dirty_submodule = 0;

	/*
	 * New file in the index: it might actually be different in
	 * the working tree.
	 */
	if (get_stat_data(new_file, &oid, &mode, cached, match_missing,
	    &dirty_submodule, &revs->diffopt) < 0)
		return;

	diff_index_show_file(revs, "+", new_file, oid, !is_null_oid(oid), mode, dirty_submodule);
}
Example #3
0
void main(int argc, char *argv[])
{
	int cpus = (int)sysconf(_SC_NPROCESSORS_CONF);
	size_t page_size = (size_t)sysconf(_SC_PAGESIZE);
	unsigned long phys_pages = sysconf(_SC_PHYS_PAGES);
	unsigned long max_pages = (phys_pages * 2); /* 2x is arbitrary */
	unsigned long cpu_counters[cpus];
	unsigned long mem_random_counter, mem_recent_counter;
	pthread_t mem_random_worker, mem_recent_worker;
	unsigned long init_mem_size = calc_init_mem_size();
	unsigned long inc_mem_size = calc_inc_mem_size();
	unsigned long bl_cpu_count = 0, bl_random_count = 0, bl_recent_count = 0;
	unsigned long alloc_cpu_count, alloc_random_count, alloc_recent_count, alloc_ms;
	long alloc_loads;
	double used_mem;
	struct timespec before, after;
	int a;

	for (a=1; a<argc; a++) {
		if (!strcmp("-nocpu", argv[a]))
			no_cpu = 1;
		else if (!strcmp("-norandom", argv[a]))
			no_random = 1;
		else if (!strcmp("-norecent", argv[a]))
			no_recent = 1;
		else if (!strcmp("-nofillpages", argv[a]))
			random_fill_pages = 0;
		else if (!strcmp("-halffillpages", argv[a]))
			random_fill_pages = 1;
		else if (!strcmp("-fillpages", argv[a]))
			random_fill_pages = 2;
		else if (!strcmp("-worktime", argv[a]))
			work_sleep_time = atoi(argv[++a]);
		else if (!strcmp("-recentpages", argv[a]))
			recent_pages = atoi(argv[++a]);
		else if (!strcmp("-help", argv[a]) || !strcmp("-h", argv[a])) {
			show_help(argv);
			return;
		} else {
			printf("Invalid opt : %s\n",argv[a]);
			show_help(argv);
			return;
		}
	}

	pages = calloc(max_pages, sizeof(void*));

	create_base_page(page_size);

	printf("Version %d\n",VERSION);

	printf("zswap max pool pct %d\n", get_zswap_max_pool());

	printf("Getting baseline numbers\n");
	fflush(NULL);

	if (!no_cpu) {
		start_cpu_workers(cpus, cpu_counters);
		bzero(cpu_counters, cpus * sizeof(unsigned long));
		sleep(work_sleep_time);
		bl_cpu_count = calc_counter(cpu_counters, cpus);

		cpu_workers_pause = 1;
	}

	page_count += alloc_pages(&pages[page_count], page_size, page_size * recent_pages * 1024);

	if (!no_random) {
		pthread_create(&mem_random_worker, NULL, &random_page_worker, &mem_random_counter);
		mem_random_counter = 0;
		sleep(work_sleep_time);
		bl_random_count = mem_random_counter;

		mem_random_pause = 1;
	}

	if (!no_recent) {
		pthread_create(&mem_recent_worker, NULL, &recent_page_worker, &mem_recent_counter);
		mem_recent_counter = 0;
		sleep(work_sleep_time);
		bl_recent_count = mem_recent_counter;
	}

	printf("Baseline CPU %ld MEM random %ld recent %ld\n", bl_cpu_count, bl_random_count, bl_recent_count);

	printf("Allocating %ldm of initial memory\n", init_mem_size / (1024 * 1024));
	fflush(NULL);
	page_count += alloc_pages(&pages[page_count], page_size, init_mem_size);

	cpu_workers_pause = 0;
	mem_random_pause = 0;
	sleep(1);

	switch (random_fill_pages) {
	case 1: printf("Allocated pages half-filled with random numbers\n"); break;
	case 2: printf("Allocated pages filled with random numbers\n"); break;
	default: printf("Allocated pages zero-filled (except 1 byte to force physical page allocation)\n"); break;
	}
	printf("All mem units %% of total physical mem\n");
	printf("CPU and MEMORY units %% of baseline measurement\n");
	printf("Allocation time units ms\n");
	printf("Alloc period is when new memory is being allocated\n");
	printf("Recent page testing %dk most recently allocated pages\n",recent_pages);
	printf("Measure period is %d secs sleep delay to measure counters\n", work_sleep_time);
	printf("\n");
	printf("               |                     Measure Period                        |              Alloc Period                 |\n");
	printf("total|used|swap| CPU |  MEMORY |  MEMORY |  zswap  | user| sys | idle| iowt| alloc | CPU |  MEMORY |  MEMORY |  zswap  |\n");
	printf(" mem | mem| mem|     |  random |  recent |  loads  |     |     |     |     |  time |     |  random |  recent |  loads  |\n");
	printf("------------------------------------------------------------------------------------------------------------------------\n");
	fflush(NULL);

	do {
		if (page_count + (inc_mem_size/page_size) > max_pages) {
			printf("Too many pages allocated, exiting\n");
			break;
		}

		bzero(cpu_counters, cpus * sizeof(unsigned long));
		mem_random_counter = 0;
		mem_recent_counter = 0;
		get_frontswap_loads();
		if (clock_gettime(CLOCK_MONOTONIC_RAW, &before)) {
			printf("Error getting timestamp\n");
			break;
		}
		page_count += alloc_pages(&pages[page_count], page_size, inc_mem_size);
		if (clock_gettime(CLOCK_MONOTONIC_RAW, &after)) {
			printf("Error getting timestamp\n");
			break;
		}
		alloc_cpu_count = calc_counter(cpu_counters, cpus);
		alloc_random_count = mem_random_counter;
		alloc_recent_count = mem_recent_counter;
		alloc_ms = calc_time_diff_ms(before, after);
		alloc_loads = get_frontswap_loads();

		used_mem = calc_used_mem();
		bzero(cpu_counters, cpus * sizeof(unsigned long));
		mem_random_counter = 0;
		mem_recent_counter = 0;
		get_stat_data();
		sleep(work_sleep_time);
		get_stat_data();
		printf(" %3.0f | %2.0f | %2.0f | %3.0f | %7.3f | %7.3f | %7ld |%4ld |%4ld |%4ld |%4ld | %5ld | %3.0f | %7.3f | %7.3f | %7ld |\n",
					 used_mem,
					 calc_used_mem_noswap(),
					 calc_used_swap(),
					 pct(calc_counter(cpu_counters, cpus), bl_cpu_count),
					 pct(mem_random_counter, bl_random_count),
					 pct(mem_recent_counter, bl_recent_count),
					 get_frontswap_loads(),
					 stat_user,
					 stat_system,
					 stat_idle,
					 stat_iowait,
					 alloc_ms,
					 adj_counter_pct(alloc_cpu_count, bl_cpu_count, alloc_ms),
					 adj_counter_pct(alloc_random_count, bl_random_count, alloc_ms),
					 adj_counter_pct(alloc_recent_count, bl_recent_count, alloc_ms),
					 alloc_loads);
		fflush(NULL);
	} while (used_mem < MAX_USED_MEM);

	cpu_workers_exit = mem_random_exit = mem_recent_exit = 1;

}
Example #4
0
void
diff_archive (void)
{
  struct stat stat_data;
  int name_length;
  int status;

  errno = EPIPE;		/* FIXME: errno should be read-only */
				/* FIXME: remove perrors */

  set_next_block_after (current_header);
  decode_header (current_header, &current_stat, &current_format, 1);

  /* Print the block from `current_header' and `current_stat'.  */

  if (verbose_option)
    {
      if (now_verifying)
	fprintf (stdlis, _("Verify "));
      print_header ();
    }

  switch (current_header->header.typeflag)
    {
    default:
      WARN ((0, 0, _("Unknown file type '%c' for %s, diffed as normal file"),
		 current_header->header.typeflag, current_file_name));
      /* Fall through.  */

    case AREGTYPE:
    case REGTYPE:
    case GNUTYPE_SPARSE:
    case CONTTYPE:

      /* Appears to be a file.  See if it's really a directory.  */

      name_length = strlen (current_file_name) - 1;
      if (current_file_name[name_length] == PATHSEP)
	goto really_dir;

      if (!get_stat_data (&stat_data))
	{
	  if (current_header->oldgnu_header.isextended)
	    skip_extended_headers ();
	  skip_file ((long) current_stat.st_size);
	  goto quit;
	}

      if (!S_ISREG (stat_data.st_mode))
	{
	  report_difference (_("Not a regular file"));
	  skip_file ((long) current_stat.st_size);
	  goto quit;
	}

      stat_data.st_mode &= 07777;
      if (stat_data.st_mode != current_stat.st_mode)
	report_difference (_("Mode differs"));

#if !MSDOS && !WIN32
      /* stat() in djgpp's C library gives a constant number of 42 as the
	 uid and gid of a file.  So, comparing an FTP'ed archive just after
	 unpack would fail on MSDOS.  */
      if (stat_data.st_uid != current_stat.st_uid)
	report_difference (_("Uid differs"));
      if (stat_data.st_gid != current_stat.st_gid)
	report_difference (_("Gid differs"));
#endif

      if (stat_data.st_mtime != current_stat.st_mtime)
	report_difference (_("Mod time differs"));
      if (current_header->header.typeflag != GNUTYPE_SPARSE &&
	  stat_data.st_size != current_stat.st_size)
	{
	  report_difference (_("Size differs"));
	  skip_file ((long) current_stat.st_size);
	  goto quit;
	}

      diff_handle = open (current_file_name, O_NDELAY | O_RDONLY | O_BINARY);

      if (diff_handle < 0 && !absolute_names_option)
	{
	  char *tmpbuf = xmalloc (strlen (current_file_name) + 2);

	  *tmpbuf = PATHSEP;
	  strcpy (tmpbuf + 1, current_file_name);
	  diff_handle = open (tmpbuf, O_NDELAY | O_RDONLY);
	  free (tmpbuf);
	}
      if (diff_handle < 0)
	{
	  ERROR ((0, errno, _("Cannot open %s"), current_file_name));
	  if (current_header->oldgnu_header.isextended)
	    skip_extended_headers ();
	  skip_file ((long) current_stat.st_size);
	  report_difference (NULL);
	  goto quit;
	}

      /* Need to treat sparse files completely differently here.  */

      if (current_header->header.typeflag == GNUTYPE_SPARSE)
	diff_sparse_files (current_stat.st_size);
      else
	{
	  if (multi_volume_option)
	    {
	      assign_string (&save_name, current_file_name);
	      save_totsize = current_stat.st_size;
	      /* save_sizeleft is set in read_and_process.  */
	    }

	  read_and_process ((long) (current_stat.st_size), process_rawdata);

	  if (multi_volume_option)
	    assign_string (&save_name, NULL);
	}

      status = close (diff_handle);
      if (status < 0)
	ERROR ((0, errno, _("Error while closing %s"), current_file_name));

    quit:
      break;

#if !MSDOS
    case LNKTYPE:
      {
	dev_t dev;
	ino_t ino;

	if (!get_stat_data (&stat_data))
	  break;

	dev = stat_data.st_dev;
	ino = stat_data.st_ino;
	status = stat (current_link_name, &stat_data);
	if (status < 0)
	  {
	    if (errno == ENOENT)
	      report_difference (_("Does not exist"));
	    else
	      {
		WARN ((0, errno, _("Cannot stat file %s"), current_file_name));
		report_difference (NULL);
	      }
	    break;
	  }

	if (stat_data.st_dev != dev || stat_data.st_ino != ino)
	  {
	    char *message = (char *)
	      xmalloc (MESSAGE_BUFFER_SIZE + strlen (current_link_name));

	    sprintf (message, _("Not linked to %s"), current_link_name);
	    report_difference (message);
	    free (message);
	    break;
	  }

	break;
      }
#endif /* not MSDOS */

#ifdef S_ISLNK
    case SYMTYPE:
      {
	char linkbuf[NAME_FIELD_SIZE + 3]; /* FIXME: may be too short.  */

	status = readlink (current_file_name, linkbuf, (sizeof linkbuf) - 1);

	if (status < 0)
	  {
	    if (errno == ENOENT)
	      report_difference (_("No such file or directory"));
	    else
	      {
		WARN ((0, errno, _("Cannot read link %s"), current_file_name));
		report_difference (NULL);
	      }
	    break;
	  }

	linkbuf[status] = '\0';	/* null-terminate it */
	if (strncmp (current_link_name, linkbuf, (size_t) status) != 0)
	  report_difference (_("Symlink differs"));

	break;
      }
#endif /* not S_ISLNK */

#ifdef S_IFCHR
    case CHRTYPE:
      current_stat.st_mode |= S_IFCHR;
      goto check_node;
#endif /* not S_IFCHR */

#ifdef S_IFBLK
      /* If local system doesn't support block devices, use default case.  */

    case BLKTYPE:
      current_stat.st_mode |= S_IFBLK;
      goto check_node;
#endif /* not S_IFBLK */

#ifdef S_ISFIFO
      /* If local system doesn't support FIFOs, use default case.  */

    case FIFOTYPE:
# ifdef S_IFIFO
      current_stat.st_mode |= S_IFIFO;
# endif
      current_stat.st_rdev = 0;	/* FIXME: do we need this? */
      goto check_node;
#endif /* S_ISFIFO */

    check_node:
      /* FIXME: deal with umask.  */

      if (!get_stat_data (&stat_data))
	break;

      if (current_stat.st_rdev != stat_data.st_rdev)
	{
	  report_difference (_("Device numbers changed"));
	  break;
	}

      if (
#ifdef S_IFMT
	  current_stat.st_mode != stat_data.st_mode
#else
	  /* POSIX lossage.  */
	  (current_stat.st_mode & 07777) != (stat_data.st_mode & 07777)
#endif
	  )
	{
	  report_difference (_("Mode or device-type changed"));
	  break;
	}

      break;

    case GNUTYPE_DUMPDIR:
      {
	char *dumpdir_buffer = get_directory_contents (current_file_name, 0);

	if (multi_volume_option)
	  {
	    assign_string (&save_name, current_file_name);
	    save_totsize = current_stat.st_size;
	    /* save_sizeleft is set in read_and_process.  */
	  }

	if (dumpdir_buffer)
	  {
	    dumpdir_cursor = dumpdir_buffer;
	    read_and_process ((long) (current_stat.st_size), process_dumpdir);
	    free (dumpdir_buffer);
	  }
	else
	  read_and_process ((long) (current_stat.st_size), process_noop);

	if (multi_volume_option)
	  assign_string (&save_name, NULL);
	/* Fall through.  */
      }

    case DIRTYPE:
      /* Check for trailing /.  */

      name_length = strlen (current_file_name) - 1;

    really_dir:
      while (name_length && current_file_name[name_length] == PATHSEP)
	current_file_name[name_length--] = '\0';	/* zap / */

      if (!get_stat_data (&stat_data))
	break;

      if (!S_ISDIR (stat_data.st_mode))
	{
	  report_difference (_("No longer a directory"));
	  break;
	}

      if ((stat_data.st_mode & 07777) != (current_stat.st_mode & 07777))
	report_difference (_("Mode differs"));
      break;

    case GNUTYPE_VOLHDR:
      break;

    case GNUTYPE_MULTIVOL:
      {
	off_t offset;

	name_length = strlen (current_file_name) - 1;
	if (current_file_name[name_length] == PATHSEP)
	  goto really_dir;

	if (!get_stat_data (&stat_data))
	  break;

	if (!S_ISREG (stat_data.st_mode))
	  {
	    report_difference (_("Not a regular file"));
	    skip_file ((long) current_stat.st_size);
	    break;
	  }

	stat_data.st_mode &= 07777;
	offset = from_oct (1 + 12, current_header->oldgnu_header.offset);
	if (stat_data.st_size != current_stat.st_size + offset)
	  {
	    report_difference (_("Size differs"));
	    skip_file ((long) current_stat.st_size);
	    break;
	  }

	diff_handle = open (current_file_name, O_NDELAY | O_RDONLY | O_BINARY);

	if (diff_handle < 0)
	  {
	    WARN ((0, errno, _("Cannot open file %s"), current_file_name));
	    report_difference (NULL);
	    skip_file ((long) current_stat.st_size);
	    break;
	  }

	status = lseek (diff_handle, offset, 0);
	if (status != offset)
	  {
	    WARN ((0, errno, _("Cannot seek to %ld in file %s"),
		   offset, current_file_name));
	    report_difference (NULL);
	    break;
	  }

	if (multi_volume_option)
	  {
	    assign_string (&save_name, current_file_name);
	    save_totsize = stat_data.st_size;
	    /* save_sizeleft is set in read_and_process.  */
	  }

	read_and_process ((long) (current_stat.st_size), process_rawdata);

	if (multi_volume_option)
	  assign_string (&save_name, NULL);

	status = close (diff_handle);
	if (status < 0)
	  ERROR ((0, errno, _("Error while closing %s"), current_file_name));

	break;
      }
    }
}