@@ -1082,46 +1082,35 @@ static struct file_system_type rdt_fs_type = {
1082
1082
.kill_sb = rdt_kill_sb ,
1083
1083
};
1084
1084
1085
- static int rdtgroup_mkdir (struct kernfs_node * parent_kn , const char * name ,
1086
- umode_t mode )
1085
+ static int mkdir_rdt_prepare (struct kernfs_node * parent_kn ,
1086
+ struct kernfs_node * prgrp_kn ,
1087
+ const char * name , umode_t mode ,
1088
+ struct rdtgroup * * r )
1087
1089
{
1088
- struct rdtgroup * parent , * rdtgrp ;
1090
+ struct rdtgroup * prdtgrp , * rdtgrp ;
1089
1091
struct kernfs_node * kn ;
1090
- int ret , closid ;
1091
-
1092
- /* Only allow mkdir in the root directory */
1093
- if (parent_kn != rdtgroup_default .kn )
1094
- return - EPERM ;
1095
-
1096
- /* Do not accept '\n' to avoid unparsable situation. */
1097
- if (strchr (name , '\n' ))
1098
- return - EINVAL ;
1092
+ uint files = 0 ;
1093
+ int ret ;
1099
1094
1100
- parent = rdtgroup_kn_lock_live (parent_kn );
1101
- if (!parent ) {
1095
+ prdtgrp = rdtgroup_kn_lock_live (prgrp_kn );
1096
+ if (!prdtgrp ) {
1102
1097
ret = - ENODEV ;
1103
1098
goto out_unlock ;
1104
1099
}
1105
1100
1106
- ret = closid_alloc ();
1107
- if (ret < 0 )
1108
- goto out_unlock ;
1109
- closid = ret ;
1110
-
1111
1101
/* allocate the rdtgroup. */
1112
1102
rdtgrp = kzalloc (sizeof (* rdtgrp ), GFP_KERNEL );
1113
1103
if (!rdtgrp ) {
1114
1104
ret = - ENOSPC ;
1115
- goto out_closid_free ;
1105
+ goto out_unlock ;
1116
1106
}
1117
- rdtgrp -> closid = closid ;
1118
- list_add (& rdtgrp -> rdtgroup_list , & rdt_all_groups );
1107
+ * r = rdtgrp ;
1119
1108
1120
1109
/* kernfs creates the directory for rdtgrp */
1121
- kn = kernfs_create_dir (parent -> kn , name , mode , rdtgrp );
1110
+ kn = kernfs_create_dir (parent_kn , name , mode , rdtgrp );
1122
1111
if (IS_ERR (kn )) {
1123
1112
ret = PTR_ERR (kn );
1124
- goto out_cancel_ref ;
1113
+ goto out_free_rgrp ;
1125
1114
}
1126
1115
rdtgrp -> kn = kn ;
1127
1116
@@ -1137,27 +1126,85 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
1137
1126
if (ret )
1138
1127
goto out_destroy ;
1139
1128
1140
- ret = rdtgroup_add_files (kn , RF_CTRL_BASE );
1129
+ files = RFTYPE_BASE | RFTYPE_CTRL ;
1130
+ ret = rdtgroup_add_files (kn , files );
1141
1131
if (ret )
1142
1132
goto out_destroy ;
1143
1133
1144
1134
kernfs_activate (kn );
1145
1135
1146
- ret = 0 ;
1147
- goto out_unlock ;
1136
+ /*
1137
+ * The caller unlocks the prgrp_kn upon success.
1138
+ */
1139
+ return 0 ;
1148
1140
1149
1141
out_destroy :
1150
1142
kernfs_remove (rdtgrp -> kn );
1151
- out_cancel_ref :
1152
- list_del (& rdtgrp -> rdtgroup_list );
1143
+ out_free_rgrp :
1153
1144
kfree (rdtgrp );
1154
- out_closid_free :
1155
- closid_free (closid );
1156
1145
out_unlock :
1157
- rdtgroup_kn_unlock (parent_kn );
1146
+ rdtgroup_kn_unlock (prgrp_kn );
1147
+ return ret ;
1148
+ }
1149
+
1150
+ static void mkdir_rdt_prepare_clean (struct rdtgroup * rgrp )
1151
+ {
1152
+ kernfs_remove (rgrp -> kn );
1153
+ kfree (rgrp );
1154
+ }
1155
+
1156
+ /*
1157
+ * These are rdtgroups created under the root directory. Can be used
1158
+ * to allocate resources.
1159
+ */
1160
+ static int rdtgroup_mkdir_ctrl (struct kernfs_node * parent_kn ,
1161
+ struct kernfs_node * prgrp_kn ,
1162
+ const char * name , umode_t mode )
1163
+ {
1164
+ struct rdtgroup * rdtgrp ;
1165
+ struct kernfs_node * kn ;
1166
+ u32 closid ;
1167
+ int ret ;
1168
+
1169
+ ret = mkdir_rdt_prepare (parent_kn , prgrp_kn , name , mode , & rdtgrp );
1170
+ if (ret )
1171
+ return ret ;
1172
+
1173
+ kn = rdtgrp -> kn ;
1174
+ ret = closid_alloc ();
1175
+ if (ret < 0 )
1176
+ goto out_common_fail ;
1177
+ closid = ret ;
1178
+
1179
+ rdtgrp -> closid = closid ;
1180
+ list_add (& rdtgrp -> rdtgroup_list , & rdt_all_groups );
1181
+
1182
+ goto out_unlock ;
1183
+
1184
+ out_common_fail :
1185
+ mkdir_rdt_prepare_clean (rdtgrp );
1186
+ out_unlock :
1187
+ rdtgroup_kn_unlock (prgrp_kn );
1158
1188
return ret ;
1159
1189
}
1160
1190
1191
+ static int rdtgroup_mkdir (struct kernfs_node * parent_kn , const char * name ,
1192
+ umode_t mode )
1193
+ {
1194
+ /* Do not accept '\n' to avoid unparsable situation. */
1195
+ if (strchr (name , '\n' ))
1196
+ return - EINVAL ;
1197
+
1198
+ /*
1199
+ * If the parent directory is the root directory and RDT
1200
+ * allocation is supported, add a control rdtgroup.
1201
+ */
1202
+ if (rdt_alloc_capable && parent_kn == rdtgroup_default .kn )
1203
+ return rdtgroup_mkdir_ctrl (parent_kn , parent_kn , name , mode );
1204
+
1205
+ return - EPERM ;
1206
+ }
1207
+
1161
1208
static int rdtgroup_rmdir (struct kernfs_node * kn )
1162
1209
{
1163
1210
int ret , cpu , closid = rdtgroup_default .closid ;
0 commit comments