| 1 | /* |
|---|
| 2 | * (C) 2001 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #include <time.h> |
|---|
| 8 | #include <stdio.h> |
|---|
| 9 | #include <unistd.h> |
|---|
| 10 | #include <sys/types.h> |
|---|
| 11 | |
|---|
| 12 | #include "client.h" |
|---|
| 13 | #include "pvfs2-util.h" |
|---|
| 14 | #include "str-utils.h" |
|---|
| 15 | #include "pint-sysint-utils.h" |
|---|
| 16 | #include "pvfs2-dist-simple-stripe.h" |
|---|
| 17 | #include "pvfs2-internal.h" |
|---|
| 18 | |
|---|
| 19 | int main(int argc, char **argv) |
|---|
| 20 | { |
|---|
| 21 | int ret = -1; |
|---|
| 22 | char str_buf[256] = {0}; |
|---|
| 23 | char *filename = (char *)0; |
|---|
| 24 | PVFS_fs_id cur_fs; |
|---|
| 25 | PVFS_sysresp_create resp_create; |
|---|
| 26 | char* entry_name; |
|---|
| 27 | PVFS_object_ref parent_refn; |
|---|
| 28 | PVFS_sys_attr attr; |
|---|
| 29 | PVFS_credentials credentials; |
|---|
| 30 | PVFS_sys_dist *dist = NULL; |
|---|
| 31 | PVFS_size new_strip_size = 8192; |
|---|
| 32 | |
|---|
| 33 | if (argc != 2) |
|---|
| 34 | { |
|---|
| 35 | fprintf(stderr,"Usage: %s filename\n",argv[0]); |
|---|
| 36 | return ret; |
|---|
| 37 | } |
|---|
| 38 | filename = argv[1]; |
|---|
| 39 | |
|---|
| 40 | ret = PVFS_util_init_defaults(); |
|---|
| 41 | if (ret < 0) |
|---|
| 42 | { |
|---|
| 43 | PVFS_perror("PVFS_util_init_defaults", ret); |
|---|
| 44 | return (-1); |
|---|
| 45 | } |
|---|
| 46 | ret = PVFS_util_get_default_fsid(&cur_fs); |
|---|
| 47 | if (ret < 0) |
|---|
| 48 | { |
|---|
| 49 | PVFS_perror("PVFS_util_get_default_fsid", ret); |
|---|
| 50 | return (-1); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | if (PINT_remove_base_dir(filename,str_buf,256)) |
|---|
| 54 | { |
|---|
| 55 | if (filename[0] != '/') |
|---|
| 56 | { |
|---|
| 57 | printf("You forgot the leading '/'\n"); |
|---|
| 58 | } |
|---|
| 59 | printf("Cannot retrieve entry name for creation on %s\n", |
|---|
| 60 | filename); |
|---|
| 61 | return(-1); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | memset(&resp_create, 0, sizeof(PVFS_sysresp_create)); |
|---|
| 65 | PVFS_util_gen_credentials(&credentials); |
|---|
| 66 | |
|---|
| 67 | entry_name = str_buf; |
|---|
| 68 | attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; |
|---|
| 69 | attr.owner = credentials.uid; |
|---|
| 70 | attr.group = credentials.gid; |
|---|
| 71 | attr.perms = 1877; |
|---|
| 72 | attr.atime = attr.ctime = attr.mtime = |
|---|
| 73 | time(NULL); |
|---|
| 74 | |
|---|
| 75 | ret = PINT_lookup_parent(filename, cur_fs, &credentials, |
|---|
| 76 | &parent_refn.handle); |
|---|
| 77 | if(ret < 0) |
|---|
| 78 | { |
|---|
| 79 | PVFS_perror("PVFS_util_lookup_parent", ret); |
|---|
| 80 | return(-1); |
|---|
| 81 | } |
|---|
| 82 | parent_refn.fs_id = cur_fs; |
|---|
| 83 | |
|---|
| 84 | printf("File to be created is %s under parent %llu\n", |
|---|
| 85 | str_buf, llu(parent_refn.handle)); |
|---|
| 86 | |
|---|
| 87 | /* Lookup the distribution to use */ |
|---|
| 88 | dist = PVFS_sys_dist_lookup("simple_stripe"); |
|---|
| 89 | if (0 == dist) |
|---|
| 90 | { |
|---|
| 91 | printf("Failed to lookup distribution basic_dist."); |
|---|
| 92 | return -1; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | /* Modify a distribution parameter */ |
|---|
| 96 | ret = PVFS_sys_dist_setparam(dist, "strip_size", &new_strip_size); |
|---|
| 97 | if (0 != ret) |
|---|
| 98 | { |
|---|
| 99 | printf("Failed to set distribution parameter strip_size.\n"); |
|---|
| 100 | return -1; |
|---|
| 101 | } |
|---|
| 102 | /*printf("strip size: %i\n", |
|---|
| 103 | ((PVFS_simple_stripe_params*)dist->params)->strip_size);*/ |
|---|
| 104 | ret = PVFS_sys_create(entry_name, parent_refn, attr, |
|---|
| 105 | &credentials, dist, &resp_create, NULL, NULL); |
|---|
| 106 | if (ret < 0) |
|---|
| 107 | { |
|---|
| 108 | PVFS_perror("create failed with errcode", ret); |
|---|
| 109 | return(-1); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /* Free the distribution */ |
|---|
| 113 | PVFS_sys_dist_free(dist); |
|---|
| 114 | |
|---|
| 115 | /* print the handle */ |
|---|
| 116 | printf("--create--\n"); |
|---|
| 117 | printf("Handle: %lld\n",lld(resp_create.ref.handle)); |
|---|
| 118 | |
|---|
| 119 | ret = PVFS_sys_finalize(); |
|---|
| 120 | if (ret < 0) |
|---|
| 121 | { |
|---|
| 122 | printf("finalizing sysint failed with errcode = %d\n", ret); |
|---|
| 123 | return (-1); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | return(0); |
|---|
| 127 | } |
|---|