@@ -239,6 +239,32 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
239
239
return ret ;
240
240
}
241
241
242
+ static ssize_t dbgfs_kdamond_pid_read (struct file * file ,
243
+ char __user * buf , size_t count , loff_t * ppos )
244
+ {
245
+ struct damon_ctx * ctx = file -> private_data ;
246
+ char * kbuf ;
247
+ ssize_t len ;
248
+
249
+ kbuf = kmalloc (count , GFP_KERNEL );
250
+ if (!kbuf )
251
+ return - ENOMEM ;
252
+
253
+ mutex_lock (& ctx -> kdamond_lock );
254
+ if (ctx -> kdamond )
255
+ len = scnprintf (kbuf , count , "%d\n" , ctx -> kdamond -> pid );
256
+ else
257
+ len = scnprintf (kbuf , count , "none\n" );
258
+ mutex_unlock (& ctx -> kdamond_lock );
259
+ if (!len )
260
+ goto out ;
261
+ len = simple_read_from_buffer (buf , count , ppos , kbuf , len );
262
+
263
+ out :
264
+ kfree (kbuf );
265
+ return len ;
266
+ }
267
+
242
268
static int damon_dbgfs_open (struct inode * inode , struct file * file )
243
269
{
244
270
file -> private_data = inode -> i_private ;
@@ -258,10 +284,17 @@ static const struct file_operations target_ids_fops = {
258
284
.write = dbgfs_target_ids_write ,
259
285
};
260
286
287
+ static const struct file_operations kdamond_pid_fops = {
288
+ .open = damon_dbgfs_open ,
289
+ .read = dbgfs_kdamond_pid_read ,
290
+ };
291
+
261
292
static void dbgfs_fill_ctx_dir (struct dentry * dir , struct damon_ctx * ctx )
262
293
{
263
- const char * const file_names [] = {"attrs" , "target_ids" };
264
- const struct file_operations * fops [] = {& attrs_fops , & target_ids_fops };
294
+ const char * const file_names [] = {"attrs" , "target_ids" ,
295
+ "kdamond_pid" };
296
+ const struct file_operations * fops [] = {& attrs_fops , & target_ids_fops ,
297
+ & kdamond_pid_fops };
265
298
int i ;
266
299
267
300
for (i = 0 ; i < ARRAY_SIZE (file_names ); i ++ )
0 commit comments