Symantec logo

Defining and assigning allocation policies

The following pseudocode provides an example of using the allocation policy APIs to define and assign allocation policies.

 To define and assign an allocation policy to reallocate an existing file's data blocks to a specific volume

/* Create a data policy for moving file's data */

strcpy((char *) ap.ap_name, "Data_Mover_Policy");

ap.ap_flags = FSAP_CREATE;

ap.ap_order = FSAP_ORDER_ASGIVEN;

ap.ap_ndevs = 1;

strcpy(ap.ap_devs[0], "vol-03");

fd = open("/mnt", O_RDONLY);

vxfs_ap_define(fd, &ap, 0);

file_fd = open ("/mnt/file_to_move", O_RDONLY);

vxfs_ap_assign_file(file_fd, "Data_Mover_Policy", NULL, 0);

vxfs_ap_enforce_file(file_fd, "Data_Mover_Policy", NULL);


  Note   The vxfs_ap_enforce_file2 API reallocates blocks in a file to match allocation policies. The FSAP_ENF_STRICT flag strictly enforces allocation orders.

See the vxfs_ap_enforce_file2(3) manual page.


 To create policies that allocate new files under a directory

In this example, the files are under dir1, the metadata is allocated to vol-01, and file data is allocated to vol-02.

/* Define 2 policies */

/* Create the RAID5 policy */

strcpy((char *) ap.ap_name, "RAID5_Policy");

ap.ap_flags = FSAP_CREATE | FSAP_INHERIT;

ap.ap_order = FSAP_ORDER_ASGIVEN;

ap.ap_ndevs = 1;

strcpy(ap.ap_devs[0], "vol-02");

fd = open("/mnt", O_RDONLY);

dir_fd = open("/mnt/dir1", O_RDONLY);

vxfs_ap_define(fd, &ap, 0);

/* Create the mirror policy */

strcpy((char *) ap.ap_name, "Mirror_Policy");

ap.ap_flags = FSAP_CREATE | FSAP_INHERIT;

ap.ap_order = FSAP_ORDER_ASGIVEN;

ap.ap_ndevs = 1;

strcpy(ap.ap_devs[0], "vol-01");

vxfs_ap_define(fd, &ap, 0);

/* Assign policies to the directory */

vxfs_ap_assign_file(dir_fd, "RAID5_Policy", "Mirror_Policy",

0);

/* Create file under directory dir1 */

/* Meta and data blocks for file1 will be allocated on

vol-01 and vol-02 respectively. */

file_fd = open("/mnt/dir1/file1");

write(file_fd, buf, 1024);