* Jan Safranek <[email protected]> [2009-02-18 15:04:38]:

> Balbir Singh wrote:
>> Feature: Provide new libcgroup walk tree API
>>
>> From: Balbir Singh <[email protected]>
>>
>> This patch adds the capability to walk cgroups by providing a new API
>> called cgroup_walk_tree. The API accepts the controller to walk and the
>> order in which the directories and files must be visited. Everytime
>> a node is visited, a callback function is invoked that can act or record
>> the node being visited.
>
> I admit I don't like the callbacks, I'd prefer 'pull' type of interface  
> - something like open_group_iterator, read_group_iterator and  
> close_group_iterator functions (and iterator being some opaque  
> structure). But that's just my personal preference.
>

I thought about doing that, I was reusing the fts API and this seemed
most appropriate, given the way that FTS works itself. I'll think more
to see if I can add an iterator, but I don't promise right now.

>> libcgroup.map has been updated to reflect the same change and the prototype
>> is exported in libcgroup.h.
>>
>> I've also added test cases (tests/walk_test.c).
>>
>> Signed-off-by: Balbir Singh <[email protected]>
>> ---
>>
>>  api.c             |   90 
>> +++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  libcgroup.h       |   41 ++++++++++++++++++++++++
>>  libcgroup.map     |    6 ++++
>>  tests/Makefile    |    6 +++-
>>  tests/walk_test.c |   63 +++++++++++++++++++++++++++++++++++++
>>  5 files changed, 205 insertions(+), 1 deletions(-)
>>  create mode 100644 tests/walk_test.c
>>
>>
>> diff --git a/libcgroup.h b/libcgroup.h
>> index 4fb99ff..1ea5361 100644
>> --- a/libcgroup.h
>> +++ b/libcgroup.h
>> @@ -97,6 +97,35 @@ enum cgroup_errors {
>>      ECGSENTINEL,    /* Please insert further error codes above this */
>>  };
>>  +/*
>> + * Don't use CGROUP_WALK_TYPE_FILE right now. It is added here for
>> + * later refactoring and better implementation. Most users *should*
>> + * use CGROUP_WALK_TYPE_PRE_DIR.
>> + */
>> +enum cgroup_walk_type {
>> +    CGROUP_WALK_TYPE_PRE_DIR = 0x1, /* Pre Order Directory */
>> +    CGROUP_WALK_TYPE_POST_DIR = 0x2,        /* Post Order Directory */
>> +    CGROUP_WALK_TYPE_FILE = 0x4,    /* Post Order Directory */
>> +    CGROUP_WALK_TYPE_ALL = 0x5,     /* directories (preorder) and files */
>> +};
>
> I think with Dhaval's patch set we don't need to return files from here.  
> I'd propose to have the walking api just for directories (i.e. groups)  
> and the Dhaval's cgroup_list_controller_files() for files.
>

OK, I'll remove FILE walk

>> +
>> +enum cgroup_file_type {
>> +    CGROUP_FILE_TYPE_FILE,          /* File */
>> +    CGROUP_FILE_TYPE_DIR,           /* Directory */
>> +    CGROUP_FILE_TYPE_SL,            /* Symbolic Link */
>
> can CGROUP_FILE_TYPE_SL be ever returned? IMHO symbolic links are not  
> supported on cgroup fylesystem (at least not on my Fedora Rawhide).
>

I added it for future expansion (sysfs can do symbolic links for
example), I'll remove it and added it back if it makes sense in the
future.

>> +};
>> +
>> +struct cgroup_file_info {
>> +    enum cgroup_file_type type;
>> +    const char *path;
>> +    const char *parent;
>> +    const char *full_path;
>> +    short depth;
>> +};
>> +
>> +typedef void *(*cgroup_walk_callback)(const struct cgroup_file_info *info,
>> +                                    void *arg);
>> +
>>  #define CG_NV_MAX 100
>>  #define CG_CONTROLLER_MAX 100
>>  #define CG_VALUE_MAX 100
>> @@ -195,6 +224,18 @@ int cgroup_get_current_controller_path(pid_t pid, const 
>> char *controller,
>>   */
>>  char *cgroup_strerror(int code);
>>  +/**
>> + * Walk through the directory tree for the specified controller.
>> + * @controller: Name of the controller, for which we want to walk
>> + * the directory tree
>> + * @type: Walk through files or directories, specify walk order as well
>> + * @cb: Callback, provides information filled by the iterator and
>> + * allows implementation of customic logic
>> + * @arg: Custom argument to be used in the callback
>> + */
>> +int cgroup_walk_tree(char *controller, enum cgroup_walk_type type,
>> +                    cgroup_walk_callback cb, void *arg);
>
> Can I get also base as additional parameter? Someone might want not to  
> start at '/'.
>

Fair enough, that itself would make it an iterator :) I'll also add a
depth parameter to it.

>
> Jan

-- 
        Balbir

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to