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
vol-03
), create code similar to the following:
/* Create a data policy for moving file's data */
strcpy((char *) ap.ap_name, "Data_Mover_Policy");
ap.ap_order = FSAP_ORDER_ASGIVEN;
strcpy(ap.ap_devs[0], "vol-03");
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
.
dir1
, create code similar to the following:
strcpy((char *) ap.ap_name, "RAID5_Policy");
ap.ap_flags = FSAP_CREATE | FSAP_INHERIT;
ap.ap_order = FSAP_ORDER_ASGIVEN;
strcpy(ap.ap_devs[0], "vol-02");
dir_fd = open("/mnt/dir1", O_RDONLY);
/* Create the mirror policy */
strcpy((char *) ap.ap_name, "Mirror_Policy");
ap.ap_flags = FSAP_CREATE | FSAP_INHERIT;
ap.ap_order = FSAP_ORDER_ASGIVEN;
strcpy(ap.ap_devs[0], "vol-01");
/* Assign policies to the directory */
vxfs_ap_assign_file(dir_fd, "RAID5_Policy", "Mirror_Policy",
/* 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");