Three phase induction motor control
Both machines can act as well as a motor or a generator. This all depends on their electrical frequency in respect to the common speed. Think of the large inertia of the arrangement to understand you may also have two motors or two generators in some situations.

Given the instant mechanical speed is fixed by the inertia, a machine whose synchronous speed (given by the electrical frequency) is higher acts as a motor. A machine whose synchronous speed is lower acts as a generator.

So the solution is to supply two different frequencies to the two machines. You don't have to care about the DC stuff and the supply rectifier. It's your rail, it has plenty of power and there's no way to shove power back to the grid – the rectifier has no controls. You don't have to care about the DC voltage either, it settles to the voltage delivered by either the generator or the rectifier, whatever is higher.

EDIT: To sum it up: The frequencies of the two inverters in regard to the mechanical speed control the direction and value of the power consumed/delivered by the rotating machines, and the phase angles of the two inverters between their respective current and voltage control the direction and value of the power transferred by the inverters. These should all match, but care about losses.