[Ocfs2-tools-devel] [PATCH 12/22] tunefs rework: Add op_set_slot_count.c

Joel Becker Joel.Becker at oracle.com
Thu Jul 31 22:27:38 PDT 2008


On Fri, Aug 01, 2008 at 10:49:01AM +0800, Tao Ma wrote:
> Joel Becker wrote:
>> +static int set_slot_count_parse_option(struct tunefs_operation *op,
>> +				       char *arg)
>> +{
>> +	int rc = 1;
>> +	char *ptr = NULL;
>> +	long num_slots;
>> +
>> +	if (!arg) {
>> +		errorf("Number of slots not specified\n");
>> +		goto out;
>> +	}
>> +
>> +	num_slots = strtol(arg, &ptr, 10);
>> +	if ((num_slots == LONG_MIN) || (num_slots == LONG_MAX)) {
>> +		errorf("Number of slots is out of range: %s\n", arg);
>> +		goto out;
>> +	}
>> +	if (*ptr != '\0') {
>> +		errorf("Invalid number: \"%s\"\n", arg);
>> +		goto out;
>> +	}
>> +	if (num_slots < 1) {
>> +		errorf("At least one slot required\n");
>> +		goto out;
>> +	}
>> +	if (num_slots > INT_MAX) {
>> +		errorf("Number of slots is out of range: %s\n", arg);
>> +		goto out;
>> +	}
>> +	/*
>> +	 * We'll check the maximum number of slots after we've opened
>> +	 * the filesystem and determined the slot map format.
>> +	 */
>> +
>> +	op->to_private = (void *)num_slots;
>> +	rc = 0;
>> +
>> +out:
>> +	return rc;
>> +}
>> +
>> +static int set_slot_count_run(struct tunefs_operation *op,
>> +			      ocfs2_filesys *fs, int flags)
>> +{
>> +	errcode_t err;
>> +	int rc = 0;
>> +	int num_slots = (int)op->to_private;

> In set_slot_count_parse_option you define num_slots as "long" and here you 
> use "int". Actually it will not cause problem sine we can never has such a 
> big num_slots. But should we use the same type?

	This is intentional, because I'm using strtol(3) to parse the
number.  strtol(3) provides error reporting that atoi(3) does not.  Once
I have the value as a long, I then check the range of the value against
negative numbers and INT_MAX, thus ensuring it's a positive int. I can
then use it later as an int, which is what the slot count code wants.

Joel

-- 

"But then she looks me in the eye
 And says, 'We're going to last forever,'
 And man you know I can't begin to doubt it.
 Cause it just feels so good and so free and so right,
 I know we ain't never going to change our minds about it, Hey!
 Here comes my girl."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127



More information about the Ocfs2-tools-devel mailing list