Esempio n. 1
0
int process_incoming_command(char*incoming)
/*
Purpose:Process incoming command, presumably
        read from FIFO and sent there by sysadm/user.
Params:	incoming - raw command string itself
Return: result (0=success; nonzero=failure)
*/
{
int res=0, port;
int clientno;
int pos;
char command[MAX_STR_LEN+1], ipaddr[MAX_STR_LEN+1],
	path[MAX_STR_LEN+1], aux[MAX_STR_LEN+1];

//  sprintf(tmp, "incoming = '%s'", incoming);
//  log_it(debug, tmp);
          pos=0;
          sscanf(incoming, "%s %s %s", command, ipaddr, path);
          if (!strcmp(command, "restore"))
            { sscanf(incoming, "%s %s %s %s", command, ipaddr, path, aux); }
          else
            { aux[0] = '\0'; }

//          for(i=0; i<strlen(command); i++) { command[i]=command[i]|0x60; }
          log_it(debug, "cmd=%s ipaddr=%s path=%s", command, ipaddr, path);
          log_it(info, "%s of %s on %s <-- command received", command, path, ipaddr);
          if ((clientno = find_client_in_clientlist(ipaddr)) < 0)
            {
              log_it(error, "%s not found in clientlist; so, %s failed.", ipaddr, command);
            }
          else if (g_clientlist.el[clientno].busy == true)
            {
              log_it(error, "%s is busy; so, %s failed.", ipaddr, command);
            }
          else
            {
              g_clientlist.el[clientno].busy = true;
              port = g_clientlist.el[clientno].port;
              if (!strcmp(command, "backup"))
                { res = backup_client(ipaddr, port, path); }
              else if (!strcmp(command, "compare"))
                { res = compare_client(ipaddr, port, path); }
              else if (!strcmp(command, "restore"))
                { res = restore_client(ipaddr, port, path, aux); }
              else
                {
                  log_it(error, "%s - cannot '%s'. Command unknown.", ipaddr, command);
                  res=1;
                }
              g_clientlist.el[clientno].busy = false;
            }
  return(res);
}
Esempio n. 2
0
/*main function*/
int main(int argc, char **argv)
{
    int opt;
    enum OPER_TYPE type;
    char path[FILE_NAME_LEN] = {0};
	char output_path[FILE_NAME_LEN] = {0};
    int delete_job;
    Client *c= NULL;
	
    if(argc<2)
  	    return -1;
	struct option long_options[] = {
		{"Simulate", 1, NULL, 'S'},
    	{"quit", 0, NULL, 'q'},
    	{"backup", 1, NULL, 'b'},
    	{"delete", 1, NULL, 'd'},
    	{"restore", 1, NULL, 'r'},
    	{"list", 0, NULL, 'l'},
    	{"pipeline", 0, NULL, 'p'},
    	{"output", 1, NULL, 'o'},
    	{"cloud", 0, NULL, 'c'},
    	
    	{"rewrite", 1, NULL, 'R'},
    	/*CFL*/
    	{"CFL", 1, NULL, 'C'},
    	{"seg_reuse", 1, NULL, 's'},
    	/*capping*/
    	{"cap_size", 1, NULL, 'a'},
    	{"cap_count", 1, NULL, 'e'},
    	/*perferect rewrite*/
    	{"ref_threshold", 1, NULL, 'u'},
    	
		{"overhead", 1, NULL, 'O'},
    	{"test", 1, NULL, 't'},
    	{"server", 1, NULL, 'H'},
    	{"help", 0, NULL, 'h'},
    	{NULL, 0, NULL, 0}
	};
	
    while((opt=getopt_long(argc, argv, "S:qb:d:r:lpo:cR:C:s:a:e:u:O:t:H:h", long_options, NULL))!=-1){
        switch(opt){
			case 'S':
				type=type_simulate;
				SIMULATE = true;
				strncpy(path, optarg, strlen(optarg));
				break;
            case 'q':
		        type=type_quit;
		        break;
            case 'b':
	  	        type=type_backup;
		        strncpy(path,optarg,strlen(optarg));
		        break;
            case 'd':
               	type=type_delete;
		        sscanf(optarg, "%d", &delete_job); 
		        break;
            case 'r':
              	type=type_restore;
		        strncpy(path,optarg,strlen(optarg));
		        break;
			case 'R':
				if (strcmp(optarg, "CFL") == 0)
					REWRITE = CFL_REWRITE;
				else if (strcmp(optarg, "CAP") == 0)
					REWRITE = CAPPING_REWRITE;
				else if (strcmp(optarg, "PER") == 0)
					REWRITE = PERFECT_REWRITE;
				break;
				
			case 'C':
				sscanf(optarg, "%f", &LWM);
				break;
			case 's':
				sscanf(optarg, "%f", &default_container_reuse);
				break;
			case 'a':
				sscanf(optarg, "%lld", &buffer_capacity);
				break;
			case 'e':
				sscanf(optarg, "%d", &max_refer_count);
				break;
			case 'u':
				sscanf(optarg, "%f", &segment_usage_threshold);
				break;
			case 'O':
				OVERHEAD = true;
				sscanf(optarg, "%f", &bandwidth);
				break;
	        case 't':
	  	        type=type_test;
		        strncpy(path,optarg,strlen(optarg));
		        break;
	        case 'h':
	   	        type=type_help;
		        break;
	            break;
            case 'H':
	  	        memset(SERVER_IP,0,30);
	  	        strncpy(SERVER_IP,optarg,strlen(optarg));
	  	        break;
			case 'l':
				type=type_list;
				break;
			case 'p':
				G_PIPELINE = true;
				break;
			case 'o':
				OUTPUT_RESULT = true;
				strncpy(output_path, optarg, strlen(optarg));
				break;
			case 'c':
				CLOUD = true;
				break;
	        default:
	   	        printf("Your command is wrong \n");
		        type=type_help;
		        break;
        }
    }

    if(type==type_help){
   	    usage(argv[0]);
	    return 0;
    }
    c = create_client();
	
	if (type == type_simulate) {
		simulata_backup(c, path, output_path);
		free(c);
		return 0;
	}else if(OVERHEAD == true) {
		backup_overhead(c, path, output_path);
		free(c);
		return 0;
	}
	
	
    if ((c->fd = bnet_connect(SERVER_IP, SERVER_PORT)) == -1){
	    err_msg1("Connection rejected!");
	    return 0;
    }

	if (G_PIPELINE) {
		c->recipe_fd = bnet_connect(SERVER_IP, SERVER_OTH_PORT);
		if (c->recipe_fd == -1) {
			err_msg1("Connection rejected!");
			return 0;
		}
	}
    
    if(type==type_test){
  	    test_data(c->fd, path);
	    return 0;
    }
    switch(type){
	    case type_login:
	        login(c);
	        break;
	    case type_logout:
	        logout(c);
	        break;
	    case type_quit:
            quit_client(c);
            break;
        case type_backup:
			if (G_PIPELINE)
				pipeline_backup(c, path, output_path);
			else
            	backup_client(c, path, output_path);
            break;
        case type_restore:
            restore_client(c, path, output_path);
            break;
        case type_delete:
            delete_client(c, delete_job);
            break;	
		case type_list:
			list_client(c);
			break;
	   default:
	   	    printf("Your command is wrong \n");
		    break;
    }
    free_client(c);
    return 0;
}