Пример #1
0
int main(int argc, char** argv)
{
  int i;
  test_reallocate();
  {
    deque_t d;
    int lots = 2;
    deque_init(4, &d, 0);
    push_front_counting(4, &d, lots);
    //print_deque(4, &d);
    pop_back_check_counting(4, &d, lots);
    //print_deque(4, &d);
    check_empty(4, &d);
    deque_destroy(&d);
  }
  for( i = 0; i < 32; i++ ) {
    test_deque(i);
  }
  for( i = 127; i < 512; i++ ) {
    test_deque(i);
  }
  test_deque(1 << 15);

  printf("deque_test PASS\n");
  return 0;
}
Пример #2
0
double check_sync(OSyncEngine *engine, const char *name, int num)
{
	int ret;
	printf(".");
	fflush(stdout);
	starttime = _second();
	osync_trace(TRACE_INTERNAL, "++++++++++++++++ Test \"%s %i\" starting ++++++++++++++", name, num);
	osengine_set_enginestatus_callback(engine, engine_status, NULL);
	sync_now(engine);
	osengine_set_enginestatus_callback(engine, NULL, NULL);
	int wasted = 0;
	int alldeciders = 0;
	osengine_get_wasted(engine, &alldeciders, &wasted);
	osync_trace(TRACE_INTERNAL, "++++++++++++++++ Test \"%s %i\" ended (%i / %i (%i%%)) ++++++++++++++", name, num, wasted, alldeciders, (int)(((float)wasted / (float)alldeciders) * 100));
	double thistime = _second() - starttime;

	printf(".");
	fflush(stdout);

	char *tempdir = g_strdup_printf("%s/plgtest.XXXXXX", g_get_tmp_dir());
	if (!mkdtemp(tempdir))
	{
		g_free(tempdir);
		osync_trace(TRACE_INTERNAL, "unable to create temporary dir: %s", g_strerror(errno));
		abort();
	}
	char *command = g_strdup_printf("mv %s/* %s &> /dev/null", localdir, tempdir);
	ret = system(command);
	if (ret)
	{
		g_free(tempdir);
		g_free(command);
		osync_trace(TRACE_INTERNAL, "Unable to move files to temporary dir: %d", ret);
		abort();
	}
	g_free(command);
	printf(".");
	fflush(stdout);

	check_empty();

	printf(".");
	fflush(stdout);

	osync_group_set_slow_sync(engine->group, "data", TRUE);

	sync_now(engine);
	printf(".");
	fflush(stdout);
	command = g_strdup_printf("test \"x$(diff -x \".*\" %s %s)\" = \"x\"", localdir, tempdir);
	int result = system(command);
	g_free(command);

	g_free(tempdir);
	if (result)
		abort();

	printf(" success\n");
	return thistime;
}
Пример #3
0
/* this function is run by the second thread */
void consumer()
{
    int i, time;
    while (1){
        
        if (i >= 32 ) {
            i = 0;
        }

        time = 0;
        
        if (!check_mutex()){
            //printf("Mutex Aquired by Consumer\n");
            if (!check_empty(i)) {
                printf("Consumer Printing from Index %d: %d\n", i, product[i].print);
                printf("Consumer Waiting at Index %d: %d\n", i, product[i].wait_time);
                time = product[i].wait_time;
                product[i].print = -1;
                product[i].wait_time = -1;
            }
            pthread_mutex_unlock(&lock);
            //printf("Mutex released by Consumer\n");
            sleep(time);

        } 
        //else {
        //    printf("Consumer did not obtain Mutex.\n");
        //}
        i++;
    }
}
Пример #4
0
int unionfs_rmdir(struct inode *dir, struct dentry *dentry)
{
	int err = 0;
	struct unionfs_dir_state *namelist = NULL;

	print_entry_location();
	lock_dentry(dentry);
	fist_print_dentry("IN unionfs_rmdir: ", dentry);

	/* check if this unionfs directory is empty or not */
	err = check_empty(dentry, &namelist);
	if (err) {
		goto out;
	}

	if (IS_SET(dir->i_sb, DELETE_WHITEOUT)) {
		/* Delete the first directory. */
		err = unionfs_rmdir_first(dir, dentry, namelist);
		/* create whiteout */
		if (!err) {
			err = create_whiteout(dentry, dbstart(dentry));
		} else {
			int new_err;

			if (dbstart(dentry) == 0)
				goto out;

			/* exit if the error returned was NOT -EROFS */
			if (!IS_COPYUP_ERR(err))
				goto out;

			new_err = create_whiteout(dentry, dbstart(dentry) - 1);
			if (new_err != -EEXIST)
				err = new_err;
		}
	} else {
		/* delete all. */
		err = unionfs_rmdir_all(dir, dentry, namelist);
	}

      out:
	/* call d_drop so the system "forgets" about us */
	if (!err)
		d_drop(dentry);

	if (namelist)
		free_rdstate(namelist);

	unlock_dentry(dentry);
	print_exit_status(err);
	return err;
}
Пример #5
0
/* We can't copyup a directory, because it may involve huge
 * numbers of children, etc.  Doing that in the kernel would
 * be bad, so instead we let the userspace recurse and ask us
 * to copy up each file separately
 */
static int may_rename_dir(struct dentry *dentry)
{
	int err, bstart;

	err = check_empty(dentry, NULL);
	if (err == -ENOTEMPTY) {
		if (is_robranch(dentry))
			return -EXDEV;
	} else if (err)
		return err;

	bstart = dbstart(dentry);
	if (dbend(dentry) == bstart || dbopaque(dentry) == bstart)
		return 0;

	set_dbstart(dentry, bstart + 1);
	err = check_empty(dentry, NULL);
	set_dbstart(dentry, bstart);
	if (err == -ENOTEMPTY)
		err = -EXDEV;
	return err;
}
Пример #6
0
char		*get_line_not_empty(int fd, int *line)
{
  char		*str;

  if ((str = get_next_line(fd)) == NULL ||
      (str = epur_str(str)) == NULL)
    return (NULL);
  (*line)++;
  while (str != NULL && check_empty(str) == 0)
    {
      if ((str = get_next_line(fd)) == NULL ||
 	  (str = epur_str(str)) == NULL)
	return (NULL);
      (*line)++;
    }
  return (str);
}
Пример #7
0
int unionfs_rmdir(struct inode *dir, struct dentry *dentry)
{
	int err = 0;
	struct unionfs_dir_state *namelist = NULL;

	unionfs_lock_dentry(dentry);

	/* check if this unionfs directory is empty or not */
	err = check_empty(dentry, &namelist);
	if (err)
		goto out;

	err = unionfs_rmdir_first(dir, dentry, namelist);
	/* create whiteout */
	if (!err)
		err = create_whiteout(dentry, dbstart(dentry));
	else {
		int new_err;

		if (dbstart(dentry) == 0)
			goto out;

		/* exit if the error returned was NOT -EROFS */
		if (!IS_COPYUP_ERR(err))
			goto out;

		new_err = create_whiteout(dentry, dbstart(dentry) - 1);
		if (new_err != -EEXIST)
			err = new_err;
	}

out:
	/* call d_drop so the system "forgets" about us */
	if (!err)
		d_drop(dentry);

	if (namelist)
		free_rdstate(namelist);

	unionfs_unlock_dentry(dentry);
	return err;
}
Пример #8
0
int		check_action(char *str, t_action *action,
			     t_pos *pos, t_ftab *ftab)
{
  char		**tab;
  t_action	*new_action;
  int		ret;

  if (!check_empty(str))
    return (0);
  if (!(new_action = create_action_list()) ||
      !(str = format_instruction(str)) ||
      !(tab = cut_instruction(str)) ||
      (ret = check_name(tab[0], new_action, pos)) == -1)
    return (1);
  if (ftab[ret] != NULL)
    {
      new_action->pos = 0;
      if (ftab[ret](new_action, tab[1], pos))
	return (1);
    }
  add_action(action, new_action);
  return (0);
}
Пример #9
0
static void empty_all(OSyncEngine *engine)
{
	printf(".");
	fflush(stdout);

	osync_group_set_slow_sync(engine->group, "data", TRUE);
	sync_now(engine);

	char *command = g_strdup_printf("rm -f %s/*", localdir);
	int ret = system(command);
	if (ret)
	{
		osync_trace(TRACE_INTERNAL, "Unable to delete data: %d", ret);
		abort();
	}
	g_free(command);
	sync_now(engine);

	printf(".");
	fflush(stdout);

	check_empty();

}
Пример #10
0
int unionfs_rmdir(struct inode *dir, struct dentry *dentry)
{
	int err = 0;
	struct unionfs_dir_state *namelist = NULL;

	print_entry_location();
	lock_dentry(dentry);
	fist_print_dentry("IN unionfs_rmdir: ", dentry);

	/* check if this unionfs directory is empty or not */
	err = check_empty(dentry, &namelist);
	if (err) {
#if 0
		/* vfs_rmdir(our caller) unhashed the dentry.  This will recover
		 * the Unionfs inode number for the directory itself, but the 
		 * children are already lost.  It seems that tmpfs manages its
		 * way around this by upping the refcount on everything.
		 *
		 * Even if we do this, we still lose the inode numbers of the
		 * children.  The best way to fix this is to fix the VFS (or
		 * use persistent inode maps). */
		if (d_unhashed(dentry))
			d_rehash(dentry);
#endif
		goto out;
	}
#ifdef UNIONFS_DELETE_ALL
	if (IS_SET(dir->i_sb, DELETE_ALL)) {
		/* delete all. */
		err = unionfs_rmdir_all(dir, dentry, namelist);
	} else {		/* Delete the first directory. */
#endif
		err = unionfs_rmdir_first(dir, dentry, namelist);
		/* create whiteout */
		if (!err) {
			err = create_whiteout(dentry, dbstart(dentry));
		} else {
			int new_err;

			if (dbstart(dentry) == 0)
				goto out;

			/* exit if the error returned was NOT -EROFS */
			if (!IS_COPYUP_ERR(err))
				goto out;

			new_err = create_whiteout(dentry, dbstart(dentry) - 1);
			if (new_err != -EEXIST)
				err = new_err;
		}

#ifdef UNIONFS_DELETE_ALL
	}
#endif
      out:
	/* call d_drop so the system "forgets" about us */
	if (!err)
		d_drop(dentry);

	if (namelist)
		free_rdstate(namelist);

	unlock_dentry(dentry);
	print_exit_status(err);
	return err;
}
Пример #11
0
void test_deque(int lots)
{
  deque_t d;
  // test: space for zeros.
  deque_init(4, &d, 0);
  check_empty(4, &d);
  deque_destroy(&d);

  // test: space for zeros.
  deque_init(4, &d, 10);
  pop_back_check_constant(4, &d, 10, 0);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: space for zeros.
  deque_init(4, &d, 10);
  pop_front_check_constant(4, &d, 10, 0);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push back lots, destroy
  deque_init(4, &d, 0);
  push_back_counting(4, &d, lots);
  iterate_counting(4, &d, lots);
  deque_destroy(&d);
  // test: push back lots, pop front lots.
  deque_init(4, &d, 0);
  push_back_counting(4, &d, lots);
  iterate_counting(4, &d, lots);
  pop_front_check_counting(4, &d, lots);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push back lots, pop back lots.
  deque_init(4, &d, 0);
  push_back_counting(4, &d, lots);
  pop_back_check_counting_reverse(4, &d, lots);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push front lots, pop front lots.
  deque_init(4, &d, 0);
  push_front_counting(4, &d, lots);
  iterate_counting_reverse(4, &d, lots);
  //print_deque(4, &d);
  pop_front_check_counting_reverse(4, &d, lots);
  //print_deque(4, &d);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push front lots, pop back lots.
  deque_init(4, &d, 0);
  push_front_counting(4, &d, lots);
  //print_deque(4, &d);
  pop_back_check_counting(4, &d, lots);
  //print_deque(4, &d);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push both lots, pop back lots, pop back lots.
  deque_init(4, &d, 0);
  push_both_counting(4, &d, lots);
  //print_deque(4, &d);
  pop_back_check_counting_reverse(4, &d, lots);
  pop_back_check_counting(4, &d, lots);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push both lots, pop front lots, pop front lots.
  deque_init(4, &d, 0);
  push_both_counting(4, &d, lots);
  //print_deque(4, &d);
  pop_front_check_counting_reverse(4, &d, lots);
  pop_front_check_counting(4, &d, lots);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push both lots, pop back lots, pop front lots
  deque_init(4, &d, 0);
  push_both_counting(4, &d, lots);
  //print_deque(4, &d);
  pop_back_check_counting_reverse(4, &d, lots);
  pop_front_check_counting_reverse(4, &d, lots);
  check_empty(4, &d);
  deque_destroy(&d);
  // test: push both lots, pop front lots, pop back lots
  deque_init(4, &d, 0);
  push_both_counting(4, &d, lots);
  //print_deque(4, &d);
  pop_front_check_counting_reverse(4, &d, lots);
  pop_back_check_counting_reverse(4, &d, lots);
  check_empty(4, &d);
  deque_destroy(&d);
}
Пример #12
0
int unionfs_rename(struct inode *old_dir, struct dentry *old_dentry,
		   struct inode *new_dir, struct dentry *new_dentry)
{
	int err = 0;
	struct dentry *wh_dentry;

	double_lock_dentry(old_dentry, new_dentry);

	if (!S_ISDIR(old_dentry->d_inode->i_mode))
		err = unionfs_partial_lookup(old_dentry);
	else
		err = may_rename_dir(old_dentry);

	if (err)
		goto out;

	err = unionfs_partial_lookup(new_dentry);
	if (err)
		goto out;

	/*
	 * if new_dentry is already hidden because of whiteout,
	 * simply override it even if the whiteouted dir is not empty.
	 */
	wh_dentry = lookup_whiteout(new_dentry);
	if (!IS_ERR(wh_dentry))
		dput(wh_dentry);
	else if (new_dentry->d_inode) {
		if (S_ISDIR(old_dentry->d_inode->i_mode) !=
		    S_ISDIR(new_dentry->d_inode->i_mode)) {
			err = S_ISDIR(old_dentry->d_inode->i_mode) ?
					-ENOTDIR : -EISDIR;
			goto out;
		}

		if (S_ISDIR(new_dentry->d_inode->i_mode)) {
			struct unionfs_dir_state *namelist;
			/* check if this unionfs directory is empty or not */
			err = check_empty(new_dentry, &namelist);
			if (err)
				goto out;

			if (!is_robranch(new_dentry))
				err = delete_whiteouts(new_dentry,
						       dbstart(new_dentry),
						       namelist);

			free_rdstate(namelist);

			if (err)
				goto out;
		}
	}
	err = do_unionfs_rename(old_dir, old_dentry, new_dir, new_dentry);

out:
	if (err)
		/* clear the new_dentry stuff created */
		d_drop(new_dentry);
	else
		/* force re-lookup since the dir on ro branch is not renamed,
		   and hidden dentries still indicate the un-renamed ones. */
		if (S_ISDIR(old_dentry->d_inode->i_mode))
			atomic_dec(&UNIONFS_D(old_dentry)->generation);

	unionfs_unlock_dentry(new_dentry);
	unionfs_unlock_dentry(old_dentry);
	return err;
}
Пример #13
0
int unionfs_rename(struct inode *old_dir, struct dentry *old_dentry,
		   struct inode *new_dir, struct dentry *new_dentry)
{
	int err = 0;
	struct dentry *wh_dentry;

	print_entry_location();

	double_lock_dentry(old_dentry, new_dentry);

	fist_checkinode(old_dir, "unionfs_rename-old_dir");
	fist_checkinode(new_dir, "unionfs_rename-new_dir");
	fist_print_dentry("IN: unionfs_rename, old_dentry", old_dentry);
	fist_print_dentry("IN: unionfs_rename, new_dentry", new_dentry);

	if (!S_ISDIR(old_dentry->d_inode->i_mode))
	err = unionfs_partial_lookup(old_dentry);
	else
		err = may_rename_dir(old_dentry);
	if (err)
		goto out;
	err = unionfs_partial_lookup(new_dentry);
	if (err)
		goto out;

	/*
	 * if new_dentry is already hidden because of whiteout,
	 * simply override it even if the whiteouted dir is not empty.
	 */
	wh_dentry = lookup_whiteout(new_dentry);
	if (!IS_ERR(wh_dentry))
		DPUT(wh_dentry);
	else if (new_dentry->d_inode) {
		if (S_ISDIR(old_dentry->d_inode->i_mode) !=
		    S_ISDIR(new_dentry->d_inode->i_mode)) {
			err =
			    S_ISDIR(old_dentry->d_inode->
				    i_mode) ? -ENOTDIR : -EISDIR;
			goto out;
		}

		if (S_ISDIR(old_dentry->d_inode->i_mode)) {
			/* check if this unionfs directory is empty or not */
			err = check_empty(new_dentry, NULL);
			if (err)
				goto out;
			/* Handle the case where we are overwriting directories
			 * that are not really empty because of whiteout or
			 * non-whiteout entries.
			 */
		}
	}
#ifdef UNIONFS_DELETE_ALL
	if (IS_SET(old_dir->i_sb, DELETE_ALL))
		err = unionfs_rename_all(old_dir, old_dentry, new_dir,
					 new_dentry);
	else
#endif
		err = unionfs_rename_whiteout(old_dir, old_dentry, new_dir,
					      new_dentry);

      out:
	fist_checkinode(new_dir, "post unionfs_rename-new_dir");
	fist_print_dentry("OUT: unionfs_rename, old_dentry", old_dentry);

	if (err) {
		/* clear the new_dentry stuff created */
		d_drop(new_dentry);
	} else {
		/* force re-lookup since the dir on ro branch is not renamed,
		   and hidden dentries still indicate the un-renamed ones. */
		if (S_ISDIR(old_dentry->d_inode->i_mode))
			atomic_dec(&dtopd(old_dentry)->udi_generation);
		fist_print_dentry("OUT: unionfs_rename, new_dentry",
				  new_dentry);
	}

	unlock_dentry(new_dentry);
	unlock_dentry(old_dentry);
	print_exit_status(err);
	return err;
}
int minimax(struct Node *current,char turn,char matrix[3][3][3][3],char main_matrix[3][3],char x,char y,char w, char z,char maxd)
	{
		count ++;
		printf("%d\n",count);
		char mind,maxi,maxival;
		if(maxd>=0)
			{
			mind=maxd;
	
		int p,i,j,f,l,*empty,k,move;
		char a,b,c,d;
		empty = NULL;
		char copy[3][3][3][3];
		for(i=0;i<81;i++)
			current->child[i]=NULL;
		if (check_winner(matrix[w][z])=='x')
			{
				main_matrix[w][z]='x';
				printf("one");
				if(check_win_main(main_matrix)=='x')
					{
						printf("two");
						current->val=1;
						current->depth=0;
						return 1;
					}
				else
					if(check_win_main(main_matrix)=='t')
					{
						current->val=0;
						current->depth=0;
						return 0;
					}

			}
		else
			if (check_winner(matrix[w][z])=='o')
				{
					
					main_matrix[w][z]='o';
		//			printmatrix2d(main_matrix);
					if(check_win_main(main_matrix)=='o')
						{
							current->val=-1;
							current->depth=0;
							return -1;
						}
					else
						if(check_win_main(main_matrix)=='t')
						{
							current->val=0;
							current->depth=0;
							return 0;
						}
				}
	
		empty=check_empty(matrix,main_matrix,x,y);
	//	printf("empty 0 = %d\n",empty[0]);
		for(i=0;empty[i]!=-1&&i<81;i++)
			{
		//		printf("Inside Loop---%d\n",i);
				a=empty[i]/1000;
				b=empty[i]/100 - a*10;
				c=empty[i]/10 - a*100 - b*10;
				d=empty[i]-a*1000 - b*100 - c*10;
				for(p=0;p<3;p++)
                        	{
                        	for(j=0;j<3;j++)
                                {
                                        for(f=0;f<3;f++)
                                                {
                                                        for(l=0;l<3;l++)
                                                                {
                                                                	copy[p][j][f][l]=matrix[p][j][f][l]; 
                                                                }
                                                }
                                }
                       		}
                

				current->child[i]=(struct Node *) malloc(sizeof(struct Node));
//				if(turn == 'x')
//					{
//					copy[a][b][c][d]='x';
//					minimax(current->child[i],'o',copy,main_matrix,c,d,a,b);
//					}
//				else
//					{
//					copy[a][b][c][d]='o';
//					minimax(current->child[i],'x',copy,main_matrix,c,d,a,b);
//					}
//
			if(i!=0)
				{
					if(turn=='x')
					{
						copy[a][b][c][d]=='x';
						if(maxival==1)
						{
							k=minimax(current->child[i],'o',copy,main_matrix,c,d,a,b,mind-1);
							if(k==1)
							{
								current->depth=(current->child[i])->depth+1;
								mind=current->depth;
								maxi=i;
							}
						}
						else
						{
							k=minimax(current->child[i],'o',copy,main_matrix,c,d,a,b,82);
							if(k==maxival)
							{
								if (((current->child[i])->depth + 1)>maxd)
								{
									current->depth=((current->child[i])->depth + 1);
									maxi=i;
									maxd=current->depth;
								}
							}
							else
							{
								if(k>maxival)
								{
									current->depth=((current->child[i])->depth + 1);
									maxd=current->depth;
									maxi=i;
									maxival=k;
								}
							}
								
						}	
					}
					else
						{
						 copy[a][b][c][d]=='o';
                                                if(maxival==-1)
                                                {
                                                        k=minimax(current->child[i],'x',copy,main_matrix,c,d,a,b,mind-1);
                                                        if(k==1)
                                                        {
                                                                current->depth=(current->child[i])->depth+1;
                                                                mind=current->depth;
                                                                maxi=i;
                                                        }
                                                }
                                                else
                                                {
                                                        k=minimax(current->child[i],'x',copy,main_matrix,c,d,a,b,82);
                                                        if(k==maxival)
                                                        {
                                                                if (((current->child[i])->depth + 1)>maxd)
                                                                {
                                                                        current->depth=((current->child[i])->depth + 1);
                                                                        maxi=i;
                                                                        maxd=current->depth;
                                                                }
                                                        }
                                                        else
                                                        {
                                                                if(k<maxival&&k!=-2)
                                                                {
                                                                        current->depth=((current->child[i])->depth + 1);
                                                                        maxd=current->depth;
                                                                        maxi=i;
                                                                        maxival=k;
                                                                }
                                                        }
                                                                
                                                }
						}
						} 
						                                                
				else
				{
					if(turn=='x')
					{
						copy[a][b][c][d]='x';
						maxival=minimax(current->child[i],'x',copy,main_matrix,c,d,a,b,82);
						maxi=i;
						current->depth=((current->child[i])->depth + 1);
						if(maxival=1)
							mind=current->depth;
					}
					else
					{
						copy[a][b][c][d]='o';
                                                maxival=minimax(current->child[i],'o',copy,main_matrix,c,d,a,b,82);
                                                maxi=i;
                                                current->depth=((current->child[i])->depth + 1);
						if(maxival==-1)
							mind=current->depth;
					}
				}
			
					
					
			}
//		if(turn=='x')
//			k=maxmove(current);
//		else
//			k=minmove(current);
//		current->depth=(current->child[k])->depth + 1;
		move=empty[maxi];
		free(empty);
		empty=NULL;
		return maxival;
		 }
		 else
		 return -2;
			
	}
Пример #15
0
/**
 * Parse a directory tree from the given XML source into the given index data structure.
 * @param reader the XML source
 * @param parent Directory where the new subdirectory should be created, or NULL to populate the
 *               root dentry.
 * @param idx LTFS index data
 * @param vol LTFS volume to which the index belongs. May be NULL.
 * @return 0 on success or a negative value on error
 */
int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent,
	struct ltfs_index *idx, struct ltfs_volume *vol, struct name_list *dirname)
{
	int ret;
	unsigned long long value_int;
	struct dentry *dir;
	declare_parser_vars("directory");
	declare_tracking_arrays(9, 1);

	if (! parent && idx->root) {
		dir = idx->root;
		dir->vol = vol;
	} else {
		dir = fs_allocate_dentry(parent, NULL, NULL, true, false, false, idx);
		if (! dir) {
			ltfsmsg(LTFS_ERR, "10001E", __FUNCTION__);
			return -LTFS_NO_MEMORY;
		}
		if (! parent) {
			idx->root = dir;
			dir->vol = vol;
			++dir->link_count;
		}
	}

	while (true) {
		get_next_tag();

		if (!strcmp(name, "name")) {
			check_required_tag(0);

			if (parent) {
				get_tag_text();
				if (xml_parse_filename(&dir->name, value) < 0)
					return -1;
				dirname->name = dir->name;
				dirname->d = dir;
				check_tag_end("name");
			} else {
				/* this is the root directory, so set the volume name */
				check_empty();
				if (empty > 0) {
					value = NULL;
				} else {
					if (xml_scan_text(reader, &value) < 0)
						return -1;
				}

				if (value && strlen(value) > 0) {
					if (xml_parse_filename(&idx->volume_name, value) < 0)
						return -1;
					/* if the value is the empty string, then xml_scan_text consumed the "name"
					 * element end */
					check_tag_end("name");
				} else
					idx->volume_name = NULL;
			}

		} else if (!strcmp(name, "readonly")) {
			check_required_tag(1);
			get_tag_text();
			if (xml_parse_bool(&dir->readonly, value) < 0)
				return -1;
			check_tag_end("readonly");

		} else if (!strcmp(name, "modifytime")) {
			check_required_tag(2);
			get_tag_text();
			ret = xml_parse_time(true, value, &dir->modify_time);
			if (ret < 0)
				return -1;
			else if (ret == LTFS_TIME_OUT_OF_RANGE)
				ltfsmsg(LTFS_WARN, "17220W", "updatetime", dir->name, dir->uid, value);

			check_tag_end("modifytime");

		} else if (!strcmp(name, "creationtime")) {
			check_required_tag(3);
			get_tag_text();
			ret = xml_parse_time(true, value, &dir->creation_time);
			if (ret < 0)
				return -1;
			else if (ret == LTFS_TIME_OUT_OF_RANGE)
				ltfsmsg(LTFS_WARN, "17220W", "creationtime", dir->name, dir->uid, value);

			check_tag_end("creationtime");

		} else if (!strcmp(name, "accesstime")) {
			check_required_tag(4);
			get_tag_text();
			ret = xml_parse_time(true, value, &dir->access_time);
			if (ret < 0)
				return -1;
			else if (ret == LTFS_TIME_OUT_OF_RANGE)
				ltfsmsg(LTFS_WARN, "17220W", "accesstime", dir->name, dir->uid, value);

			check_tag_end("accesstime");

		} else if (!strcmp(name, "changetime")) {
			check_required_tag(5);
			get_tag_text();
			ret = xml_parse_time(true, value, &dir->change_time);
			if (ret < 0)
				return -1;
			else if (ret == LTFS_TIME_OUT_OF_RANGE)
				ltfsmsg(LTFS_WARN, "17220W", "changetime", dir->name, dir->uid, value);

			check_tag_end("changetime");

		} else if (! strcmp(name, "contents")) {
			check_required_tag(6);
			check_empty();
			if (empty == 0 && (ret = _xml_parse_dir_contents(reader, dir, idx)) < 0) {
				if (ret == -LTFS_NO_MEMORY)
					return ret;
				else
					return -1;
			}

		} else if (!strcmp(name, "extendedattributes")) {
			check_optional_tag(0);
			check_empty();
			if (empty == 0 && _xml_parse_xattrs(reader, dir) < 0)
					return -1;

		} else if (idx->version >= IDX_VERSION_UID && ! strcmp(name, UID_TAGNAME)) {
			check_required_tag(7);
			get_tag_text();
			if (xml_parse_ull(&value_int, value) < 0)
				return -1;
			dir->uid = value_int;
			if (dir->uid > idx->uid_number)
				idx->uid_number = dir->uid;
			if (parent) {
				dirname->uid  = dir->uid;
			}
			check_tag_end(UID_TAGNAME);
		} else if (! strcmp(name, UID_TAGNAME)) {
			ignore_unrecognized_tag();

		} else if (idx->version >= IDX_VERSION_BACKUPTIME && ! strcmp(name, BACKUPTIME_TAGNAME)) {
			check_required_tag(8);
			get_tag_text();
			ret = xml_parse_time(true, value, &dir->backup_time);
			if (ret < 0)
				return -1;
			else if (ret == LTFS_TIME_OUT_OF_RANGE)
				ltfsmsg(LTFS_WARN, "17220W", "backuptime", dir->name, dir->uid, value);

			check_tag_end(BACKUPTIME_TAGNAME);
		} else if (! strcmp(name, BACKUPTIME_TAGNAME)) {
			ignore_unrecognized_tag();

		} else
			preserve_unrecognized_tag(dir);
	}

	/* For old index versions, allocate a UID */
	if (idx->version < IDX_VERSION_UID) {
		check_required_tag(7);
		if (parent) {
			dir->uid = fs_allocate_uid(idx);
			if (dir->uid > idx->uid_number)
				idx->uid_number = dir->uid;
			dirname->uid  = dir->uid;
		}
		/* root directory already got assigned UID 1 by fs_allocate_dentry */
	}

	/* For old index versions, set backup time equal to creation time */
	if (idx->version < IDX_VERSION_BACKUPTIME) {
		check_required_tag(8);
		dir->backup_time = dir->creation_time;
	}

	check_required_tags();

	/* Validate UID: root directory must have uid==1, other dentries must have nonzero UID */
	/* TODO: would be nice to verify that there are no UID conflicts */
	if (parent && dir->uid == 1) {
		ltfsmsg(LTFS_ERR, "17101E");
		return -1;
	} else if (! parent && dir->uid != 1) {
		ltfsmsg(LTFS_ERR, "17100E");
		return -1;
	} else if (dir->uid == 0) {
		ltfsmsg(LTFS_ERR, "17106E");
		return -1;
	}

	return 0;
}
Пример #16
0
int basic_insertion_test()
{
	long result = errors_counter();

	typedef containers::ternary_tree<std::basic_string<CharT>, int> Tst;
	Tst tst;

	const char* strings[] = { "\0", "aa", "aab", "aac", "add", "aee", "bab" };
	widen<CharT> w;

	// Construction postconditions
	check_empty(tst);

	// Standard insert()
	tst.insert(std::make_pair(w(strings[1]), 1));
	tst.insert(std::make_pair(w(strings[5]), 5));

	std::pair<std::basic_string<CharT>, int> inval(w(strings[3]), 3);
	std::pair<Tst::iterator, bool> vr = tst.insert(inval);
	BOOST_CHECK(vr.first != tst.end());
	BOOST_CHECK(vr.second == true);
	vr = tst.insert(inval);
	BOOST_CHECK(vr.first != tst.end());
	BOOST_CHECK(vr.second == false);

	BOOST_CHECK((*tst.find(w(strings[1]))) == 1);
	BOOST_CHECK((*tst.find(w(strings[3]))) == 3);
	BOOST_CHECK((*tst.find(w(strings[5]))) == 5);

	BOOST_CHECK(tst.item_count() == 3);
	BOOST_CHECK(tst.total_key_length() == 3*3-1);

	// In present version, no reassignment
	tst.insert(std::make_pair(w(strings[1]), 4));
	BOOST_CHECK((*tst.find(w(strings[1]))) == 1);
	BOOST_CHECK(tst.item_count() == 3);
	BOOST_CHECK(tst.total_key_length() == 3*3-1);

	// reference_proxy insert()
	tst[w(strings[2])] = 2;
	tst[w(strings[6])] = 6;
	tst[w(strings[4])] = 4;
	BOOST_CHECK(tst[w(strings[2])] == 2);
	BOOST_CHECK(tst[w(strings[4])] == 4);
	BOOST_CHECK(tst[w(strings[6])] == 6);

	BOOST_CHECK(tst.item_count() == 6);
	BOOST_CHECK(tst.total_key_length() == 6*3-1);

	// Now do reassignment
	tst[w(strings[1])] = 7;
	BOOST_CHECK((*tst.find(w(strings[1]))) == 7);  //1);
	tst[w(strings[1])] = 1;

	// iterator used to check sort order of strings
	Tst::const_iterator it(tst.begin());
	int expect_val = 1;
	while (it != tst.end()) {
		Tst::value_type val = *it;
		// string == "a", "b" etc
		BOOST_CHECK(expect_val == 1 || it.key().size() == 3);
		BOOST_CHECK(it.key() == w(strings[expect_val]));
		// value is 1, 2 etc
		BOOST_CHECK(val == expect_val++);
		++it;
	}
	BOOST_CHECK(expect_val == int(tst.item_count() + 1));

	// Test clear() postconditions
	tst.clear();

	check_empty(tst);

	return errors_counter() - result;
}
void test(const Cont &)
{
  // Testing if all types are provided.

  typename Cont::value_type              t0;
  typename Cont::reference               t1 = t0;      CGAL_USE(t1);
  typename Cont::const_reference         t2 = t0;      CGAL_USE(t2);
  typename Cont::pointer                 t3 = &t0;
  typename Cont::const_pointer           t4 = &t0;     CGAL_USE(t4);
  typename Cont::size_type               t5 = 0;       CGAL_USE(t5);
  typename Cont::difference_type         t6 = t3-t3;   CGAL_USE(t6);
  typename Cont::iterator                t7;           CGAL_USE(t7);
  typename Cont::const_iterator          t8;           CGAL_USE(t8);
  typename Cont::reverse_iterator        t9;           CGAL_USE(t9);
  typename Cont::const_reverse_iterator  t10;          CGAL_USE(t10);
  typename Cont::allocator_type          t15;

  std::cout << "Testing empty containers." << std::endl;

  Cont c0, c1;
  Cont c2(t15);
  Cont c3(c2);
  Cont c4;
  c4 = c2;

  typedef std::vector<typename Cont::value_type> Vect;
  Vect v0;
  const Cont c5(v0.begin(), v0.end());
  Cont c6(c5.begin(), c5.end());
  typename Cont::allocator_type Al;
  Cont c7(c0.begin(), c0.end(), Al);
  Cont c8;
  c8.insert(c0.rbegin(), c0.rend());

  // test conversion iterator-> const_iterator.
  typename Cont::const_iterator t16 = c5.begin();  CGAL_USE(t16);
  assert(t16 == c5.begin());

  assert(c0 == c1);
  assert(! (c0 < c1));

  assert(check_empty(c0));
  assert(check_empty(c1));
  assert(check_empty(c2));
  assert(check_empty(c3));
  assert(check_empty(c4));
  assert(check_empty(c5));
  assert(check_empty(c6));
  assert(check_empty(c7));
  assert(check_empty(c8));

  c1.swap(c0);

  assert(check_empty(c0));
  assert(check_empty(c1));

  c1.merge(c0);

  assert(check_empty(c0));
  assert(check_empty(c1));

  typename Cont::allocator_type  t20 = c0.get_allocator();

  std::cout << "Now filling some containers" << std::endl;

  Vect v1(10000);
  Cont c9(v1.begin(), v1.end());

  assert(c9.size() == v1.size());
  assert(c9.max_size() >= v1.size());
  assert(c9.capacity() >= c9.size());

  Cont c10 = c9;

  assert(c10 == c9);
  assert(c10.size() == v1.size());
  assert(c10.max_size() >= v1.size());
  assert(c10.capacity() >= c10.size());

  c9.clear();

  assert(check_empty(c9));
  assert(c9.capacity() >= c9.size());
  assert(c0 == c9);

  c9.merge(c10);
  c10.swap(c9);

  assert(check_empty(c9));
  assert(c9.capacity() >= c9.size());

  assert(c10.size() == v1.size());
  assert(c10.max_size() >= v1.size());
  assert(c10.capacity() >= c10.size());

  std::cout << "Testing insertion methods" << std::endl;

  c9.assign(c10.begin(), c10.end());

  assert(c9 == c10);

  c10.assign(c9.begin(), c9.end());

  assert(c9 == c10);

  c9.insert(c10.begin(), c10.end());

  assert(c9.size() == 2*v1.size());

  c9.clear();

  assert(c9 != c10);

  c9.insert(c10.begin(), c10.end());

  assert(c9.size() == v1.size());
  assert(c9 == c10);


  typename Cont::iterator it = c9.iterator_to(*c9.begin());
  assert(it == c9.begin());
  typename Cont::const_iterator cit = c9.iterator_to(const_cast<typename Cont::const_reference>(*c9.begin()));
  assert(cit == c9.begin());

  typename Cont::iterator s_it = Cont::s_iterator_to(*c9.begin());
  assert(s_it == c9.begin());
  typename Cont::const_iterator s_cit = Cont::s_iterator_to(const_cast<typename Cont::const_reference>(*c9.begin()));
  assert(s_cit == c9.begin());


  c10 = Cont();

  assert(check_empty(c10));

  for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it)
    c10.insert(*it);

  assert(c10.size() == v1.size());
  assert(c9 == c10);

  c9.erase(c9.begin());
  c9.erase(c9.begin());

  assert(c9.size() == v1.size() - 2);

  // test reserve
  /*Cont c11;
  c11.reserve(v1.size());
  for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it)
    c11.insert(*it);
  
  assert(c11.size() == v1.size());
  assert(c10 == c11);*/

  // owns() and owns_dereferencable().
  for(typename Cont::const_iterator it = c9.begin(), end = c9.end(); it != end; ++it) {
    assert(c9.owns(it));
    assert(c9.owns_dereferencable(it));
    assert(! c10.owns(it));
    assert(! c10.owns_dereferencable(it));
  }
  assert(c9.owns(c9.end()));
  assert(! c9.owns_dereferencable(c9.end()));


  c9.erase(c9.begin(), c9.end());

  assert(check_empty(c9));
  
  std::cout << "Testing parallel insertion" << std::endl;
  {
  Cont c11;
  Vect v11(1000000);
  std::vector<typename Cont::iterator> iterators(v11.size());
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v11.size() ),
    Insert_in_CCC_functor<Vect, Cont>(v11, c11, iterators)
  );
  assert(c11.size() == v11.size());
  
  std::cout << "Testing parallel erasure" << std::endl;
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v11.size() ),
    Erase_in_CCC_functor<Cont>(c11, iterators)
  );
  assert(c11.empty());
  }

  std::cout << "Testing parallel insertion AND erasure" << std::endl;
  {
  Cont c12;
  Vect v12(1000000);
  std::vector<tbb::atomic<bool> > free_elements(v12.size());
  for(typename std::vector<tbb::atomic<bool> >::iterator 
    it = free_elements.begin(), end = free_elements.end(); it != end; ++it) 
  {
    *it = true;
  }
    
  tbb::atomic<unsigned int> num_erasures; 
  num_erasures = 0;
  std::vector<typename Cont::iterator> iterators(v12.size());
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v12.size() ),
    Insert_and_erase_in_CCC_functor<Vect, Cont>(
      v12, c12, iterators, free_elements, num_erasures)
  );
  assert(c12.size() == v12.size() - num_erasures);
  }
}
Пример #18
0
int main()
{
    int i;
    int producer_wait;
    for (i = 0; i < 32; ++i){
        product[i].print=-1;
        product[i].wait_time=-1;
    }

    //Prints all the data in the array.
    //for (i = 0; i < 32; ++i){
    //    printf("Print: %d\n", product[i].print);
    //    printf("Wait: %d\n", product[i].wait_time);
    //}

    /* this variable is our reference to the second thread */
    pthread_t consumer_thread;

    /* create a second thread which executes inc_x(&x) */
    if(pthread_create(&consumer_thread, NULL, (void *)consumer, (void *)NULL)) {

        fprintf(stderr, "Error creating thread\n");
        return 1;

    }
    while (1){

        if (i >= 32 ) {
            i = 0;
        }
        
        producer_wait = 0;
        
        if (!check_mutex()){
            //printf("Mutex Aquired by Producer\n");
            if (check_empty(i)) {
                product[i].print = rdrand_func(3);
                product[i].wait_time = rdrand_func(1);
                printf("Producer Inserting Value %d and Wait Time %d at Index: %d\n", product[i].print, product[i].wait_time, i);
                producer_wait = rdrand_func(2);
                printf("Producer is now sleeping for %d seconds\n", producer_wait);
            }
            pthread_mutex_unlock(&lock);
            //printf("Mutex released by Producer\n");
            sleep(producer_wait);
        } 
        
        //else {
          //  printf("Producer did not obtain Mutex.\n");
        //}
        i++;
    }
    /* wait for the second thread to finish */
    if(pthread_join(consumer_thread, NULL)) {
        fprintf(stderr, "Error joining thread\n");
        return 2;
    }

    return 0;

}
Пример #19
0
/*
 * The locking rules in unionfs_rename are complex.  We could use a simpler
 * superblock-level name-space lock for renames and copy-ups.
 */
int unionfs_rename(struct inode *old_dir, struct dentry *old_dentry,
		   struct inode *new_dir, struct dentry *new_dentry)
{
	int err = 0;
	struct dentry *wh_dentry;
	struct dentry *old_parent, *new_parent;
	int valid = true;

	unionfs_read_lock(old_dentry->d_sb, UNIONFS_SMUTEX_CHILD);
	old_parent = dget_parent(old_dentry);
	new_parent = dget_parent(new_dentry);
	/* un/lock parent dentries only if they differ from old/new_dentry */
	if (old_parent != old_dentry &&
	    old_parent != new_dentry)
		unionfs_lock_dentry(old_parent, UNIONFS_DMUTEX_REVAL_PARENT);
	if (new_parent != old_dentry &&
	    new_parent != new_dentry &&
	    new_parent != old_parent)
		unionfs_lock_dentry(new_parent, UNIONFS_DMUTEX_REVAL_CHILD);
	unionfs_double_lock_dentry(old_dentry, new_dentry);

	valid = __unionfs_d_revalidate(old_dentry, old_parent, false);
	if (!valid) {
		err = -ESTALE;
		goto out;
	}
	if (!d_deleted(new_dentry) && new_dentry->d_inode) {
		valid = __unionfs_d_revalidate(new_dentry, new_parent, false);
		if (!valid) {
			err = -ESTALE;
			goto out;
		}
	}

	if (!S_ISDIR(old_dentry->d_inode->i_mode))
		err = unionfs_partial_lookup(old_dentry, old_parent);
	else
		err = may_rename_dir(old_dentry, old_parent);

	if (err)
		goto out;

	err = unionfs_partial_lookup(new_dentry, new_parent);
	if (err)
		goto out;

	/*
	 * if new_dentry is already lower because of whiteout,
	 * simply override it even if the whited-out dir is not empty.
	 */
	wh_dentry = find_first_whiteout(new_dentry);
	if (!IS_ERR(wh_dentry)) {
		dput(wh_dentry);
	} else if (new_dentry->d_inode) {
		if (S_ISDIR(old_dentry->d_inode->i_mode) !=
		    S_ISDIR(new_dentry->d_inode->i_mode)) {
			err = S_ISDIR(old_dentry->d_inode->i_mode) ?
				-ENOTDIR : -EISDIR;
			goto out;
		}

		if (S_ISDIR(new_dentry->d_inode->i_mode)) {
			struct unionfs_dir_state *namelist = NULL;
			/* check if this unionfs directory is empty or not */
			err = check_empty(new_dentry, new_parent, &namelist);
			if (err)
				goto out;

			if (!is_robranch(new_dentry))
				err = delete_whiteouts(new_dentry,
						       dbstart(new_dentry),
						       namelist);

			free_rdstate(namelist);

			if (err)
				goto out;
		}
	}

	err = do_unionfs_rename(old_dir, old_dentry, old_parent,
				new_dir, new_dentry, new_parent);
	if (err)
		goto out;

	/*
	 * force re-lookup since the dir on ro branch is not renamed, and
	 * lower dentries still indicate the un-renamed ones.
	 */
	if (S_ISDIR(old_dentry->d_inode->i_mode))
		atomic_dec(&UNIONFS_D(old_dentry)->generation);
	else
		unionfs_postcopyup_release(old_dentry);
	if (new_dentry->d_inode && !S_ISDIR(new_dentry->d_inode->i_mode)) {
		unionfs_postcopyup_release(new_dentry);
		unionfs_postcopyup_setmnt(new_dentry);
		if (!unionfs_lower_inode(new_dentry->d_inode)) {
			/*
			 * If we get here, it means that no copyup was
			 * needed, and that a file by the old name already
			 * existing on the destination branch; that file got
			 * renamed earlier in this function, so all we need
			 * to do here is set the lower inode.
			 */
			struct inode *inode;
			inode = unionfs_lower_inode(old_dentry->d_inode);
			igrab(inode);
			unionfs_set_lower_inode_idx(new_dentry->d_inode,
						    dbstart(new_dentry),
						    inode);
		}
	}
	/* if all of this renaming succeeded, update our times */
	unionfs_copy_attr_times(old_dentry->d_inode);
	unionfs_copy_attr_times(new_dentry->d_inode);
	unionfs_check_inode(old_dir);
	unionfs_check_inode(new_dir);
	unionfs_check_dentry(old_dentry);
	unionfs_check_dentry(new_dentry);

out:
	if (err)		/* clear the new_dentry stuff created */
		d_drop(new_dentry);

	unionfs_double_unlock_dentry(old_dentry, new_dentry);
	if (new_parent != old_dentry &&
	    new_parent != new_dentry &&
	    new_parent != old_parent)
		unionfs_unlock_dentry(new_parent);
	if (old_parent != old_dentry &&
	    old_parent != new_dentry)
		unionfs_unlock_dentry(old_parent);
	dput(new_parent);
	dput(old_parent);
	unionfs_read_unlock(old_dentry->d_sb);

	return err;
}